+ 5

Concatenation of characters in Java

Can somebody explain how the line 11 works? Thanks https://code.sololearn.com/cl59bbmGNKWv/?ref=app

30th Dec 2018, 7:53 AM
Atila Sabo
Atila Sabo - avatar
4 odpowiedzi
+ 9
That's because every character have its corresponding numeric encoding value (ASCII) and you may imagine it as a mapping between each character and its binary value. In this case, '1' and '2' equivalent to 49 and 50 respectively and hence sum to 99 arithmetically. 🔗 Reference https://www.arduino.cc/en/Reference/ASCIIchart
30th Dec 2018, 8:06 AM
Zephyr Koo
Zephyr Koo - avatar
+ 8
You are actually doing an arithmetic expression when trying to do a char concatenation. The result would be the sum of numeric encoding value of the chars in either hands. Performing the concatenation after converting them to strings(using toString()) can do the thing that were in your mind.
30th Dec 2018, 8:27 AM
Seniru
Seniru - avatar
+ 3
Zephyr Koo and Seniru Pasan thank you for your answers!
30th Dec 2018, 8:34 AM
Atila Sabo
Atila Sabo - avatar
+ 2
Atila Sabo You're welcome! 😉
31st Dec 2018, 12:48 PM
Zephyr Koo
Zephyr Koo - avatar