+ 5

# Concatenation of characters in Java

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

4 Answers

+ 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

+ 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.

+ 3

Zephyr Koo and Seniru Pasan thank you for your answers!

+ 2

Atila Sabo You're welcome! ðŸ˜‰