+ 3
Can sameone explain why the answear is "3Solo12" instead of "3Solo3"?
The code System.out.print(1+2+"Solo"+1+2);
5 Answers
+ 9
Addition is done from left to right, so firstly 1+2 is computed and return 3 because both values are numbers, then 3+"Solo" return "3solo" because 3 is turned implicitly to string to perform number+string concanetation, and then "3Solo"+1 in same way equals "3Solo1", and finaly last "3Solo1"+2 will return still same ways "3Solo12"... if you want to get "3Solo3" you should write 1+2+"Solo"+(1+2) to modify priority of operations ^^
+ 10
Everything after "Solo" becomes a string because "Solo" is a string and when it concatenates with something else it converts to a string.
+ 4
becouse after adding string, it understands not int sum but string sum. if you wirte add +(1+2) then it adds as int sum
+ 3
Thank you :D