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

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

php - Using str_replace to translate a MySQL Table in html -

asp.net mvc - Cannot display error message on Editor or EditorFor -