+ 1
How to do coding if i want to print the middle number?
123..I want to print num 2
2 Antworten
+ 6
You can convert that number to a string and then use a split method on the string to split it into an array and then call the second element of that array. This is how it's done in Javascript, other languages might simplify this:
Example (Javascript):
var num = 123;
var str = num + "";
var strArray = str.split("");
document.write(strArray[1]);
//Outputs 2
In Javascript, you don't even need to convert the string to an array first to call it's elements but for consideration of other languages, I included all possibilities.
+ 5
use integer division and integer modulus
ex
int x = 123;
int a = x / 10; // 12
int middle = a % 10 // 2