Num = num + s.charAt(0)-'0'; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Num = num + s.charAt(0)-'0';

Why substraction of char '0'

17th Mar 2021, 6:35 AM
🤔☺️😳😇
3 Answers
+ 3
char codes: '0' : 48 '1' : 49 '2' : 50 ... digit char - '0' == numeric digit
17th Mar 2021, 6:41 AM
visph
visph - avatar
+ 1
to get numeric value of digit from its char code ^^
17th Mar 2021, 6:37 AM
visph
visph - avatar
0
I am not getting you
17th Mar 2021, 6:39 AM
🤔☺️😳😇