JavaIntermediate#puzzle#operators

What does this print? int x = 5; System.out.println(x++ + ++x);

x++ (post-increment) uses 5 then increments x to 6; ++x (pre-increment) increments x to 7 then uses 7. So the expression evaluates to 5 + 7 = 12.

Example
int x = 5;
System.out.println(x++ + ++x); // Output: 12

Related Questions

1
JavaBeginner#puzzle#strings

What is the output of this code? String s1 = "abc"; String s2 = "abc"; String s3 = new String("abc"); System.out.println(s1 == s2); System.out.println(s1 == s3);

Open
2
JavaAdvanced#puzzle#exceptions

What does this code output and why? try { return 1; } finally { return 2; }

Open
3
JavaAdvanced#puzzle#collections

What is the output? List<Integer> list = new ArrayList<>(); list.add(1); list.add(2); for (Integer i : list) { if (i == 1) list.remove(i); }

Open