0

why the output it's not 30 30 the actual output is: "30 1020"

public class YourClassNameHere { public static void main(String[] args) { int a =10; int b=20; System.out.println(a+b +" "+ a+b); } }

6th Nov 2020, 8:25 PM
Samer Mazraani
Samer Mazraani - avatar
2 Réponses
+ 6
If you want to change the order of how the expression is being evaluated, you have to use parentheses. Try this: System.out.println(a+b+" "+(a+b));
6th Nov 2020, 9:33 PM
_cm_
+ 3
Implicit string concatenation and implicit conversion is what's going on there, since the expression is evaluated from left to right
6th Nov 2020, 9:23 PM
Benjamin Jürgens
Benjamin Jürgens - avatar