java - Getting the character code for a number -


how can can char representation of integer in range 0 - 9 ?
given digit1 integer in range,
i've tried

char1 = (char) digit1; system.out.printf("%s", character.tostring(char1)); 

and also

char1 = 'digit1';   system.out.printf("%s", character.tostring(char1));   

but each time prints "weird" character whereas expecting corresponding one-digit integer.

is there i'm doing wrong in printing or somewhere else?
in advance.

you confusing value 0 ascii character '0'.

any of following work:

system.out.printf("%d", digit); system.out.printf("%c", digit + '0'); system.out.printf("%s", character.tostring((char)(digit + '0'))); 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -