You down with OOP? Yeah you know me!
That won't work.char a = '102';
int b = a.getNumericValue();
But char values already are integers. You can do arithmetic with them. Try subtracting '0' from another numeric digit and see what prints out.convert a character to integer?
You down with OOP? Yeah you know me!
and when you print it outchar c = '5'
you are converting an integer to a character. As Justin Fox and Fred Hamilton have shown, you can do arithmetic on chars, but usually you only get sensible answers with addition or subtraction.System.out.println(c);
Campbell Ritchie wrote:Welcome to JavaRanch
Jaka Barrozo.
It's not always a good idea to wake a 3-yr old thread.
What people forget is that a char is a number, not a character. When you write char c = '5'; you do not store a 5 anywhere; you store 53 or more precisely 0000_0000_0011_0101. You don't convert chars to integers at all; chars always are integers (see this Java™ Language Specification section). You convert a character to an integer when you sayand when you print it outchar c = '5'
you are converting an integer to a character. As Justin Fox and Fred Hamilton have shown, you can do arithmetic on chars, but usually you only get sensible answers with addition or subtraction.System.out.println(c);
Don't get me started about those stupid light bulbs. |