+ 3
Java question
Why System.out.print("2+2="+2+2) Is 2+2=22 instead of 2+2=4?
2 Answers
+ 2
You are adding two things to a string. The execution order is from left to right. When you add a number to a string, the number is implicitly converted to a string in the background, and the two strings are concatenated.
If you want to print the result of the numeric addition, you should use parentheses to force java to add the numbers first, then concatenate the result to the text.
System.out.print("2+2=" + (2+2))