I you have the char '9'
, it will store its ASCII code, so to get the int value, you have 2 ways
char x = '9';
int y = Character.getNumericValue(x); //use a existing function
System.out.println(y + " " + (y + 1)); // 9 10
or
char x = '9';
int y = x - '0'; // substract '0' code to get the difference
System.out.println(y + " " + (y + 1)); // 9 10
And it fact, this works also :
char x = 9;
System.out.println(">" + x + "<"); //> < prints a horizontal tab
int y = (int) x;
System.out.println(y + " " + (y + 1)); //9 10
You store the 9
code, which corresponds to a horizontal tab
(you can see when print as String
, bu you can also use it as int
as you see above