How to convert a character value into an integer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

How to convert a character value into an integer

https://code.sololearn.com/c3Kcx9qpCtOU/?ref=app

31st Dec 2019, 10:32 AM
Naman Pandey
Naman Pandey - avatar
9 Answers
+ 5
Integer.valueOf('6') == 6?
31st Dec 2019, 10:36 AM
Seb TheS
Seb TheS - avatar
+ 4
But you can convert characters by integers of the same digits only by subtracting 48. '6' - 48 == 6
31st Dec 2019, 10:42 AM
Seb TheS
Seb TheS - avatar
+ 4
you can cast the character to int this actually happens when you subtract 48 ... ((int)'6') - 48 == 6
31st Dec 2019, 10:53 AM
Anton Böhler
Anton Böhler - avatar
+ 2
Naman Pandey No, it seemed to be wrong.
31st Dec 2019, 10:38 AM
Seb TheS
Seb TheS - avatar
+ 2
char myChar = 'C'; int converted = (int) myChar; System.out.print(converted); Output: 67 Or subtract if you have a digit
31st Dec 2019, 11:52 AM
HNNX 🐿
HNNX 🐿 - avatar
+ 2
HNNX 🐿 'c' == 99, 'C' == 67
31st Dec 2019, 11:58 AM
Seb TheS
Seb TheS - avatar
+ 1
Yes,it is not working properly
31st Dec 2019, 10:42 AM
Naman Pandey
Naman Pandey - avatar
+ 1
Seb TheS fixed :)
31st Dec 2019, 12:29 PM
HNNX 🐿
HNNX 🐿 - avatar
0
Thanks
31st Dec 2019, 10:37 AM
Naman Pandey
Naman Pandey - avatar