I am new to Java and was working with simple printing. First, I executed:
System.out.println(1 + 2 + "3");
Output:33
I made up logic that 1 and 2 will be added and 3 will be printed as is.
Then, I tried this:
System.out.println ("1" + 2 + 3);
Output:123
Applying that logic I got answer 15 ,couldn’t work-out the correct answer, so I need your help, SO friends.
Operator
+is evaluated from the left so your second example is interpreted this way:If you want to display
15then you should do the following:This way
(2+3)will be evaluated first.