How can I can get the char representation of an integer in the range 0 – 9 ?
Given that digit1 is an integer in that 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 it prints a “weird” character whereas I was expecting the corresponding one-digit integer.
Is there something that I’m doing wrong in the printing or somewhere else?
THanks in advance.
You are confusing the value
0with the ASCII character'0'.Any of the following would work: