Core java printing statement -


why java compiler gives

100a

as output when ever tried print system.out.println('2'+'2'+"a") ,

a22

for system.out.println("a"+'2'+'2'). please explain in detail . thank you)

'2' char, '2' + '2' adds int value of character (50+50) , appends "a" it, giving 100a.

"a" + '2' + '2' performs string concatenation, since first operand string. therefore a22.

note expressions evaluated left right, types of first 2 operands determine whether + perform int addition or string concatenation.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -