0

This is my code snippet.

class Example{
public static void main(String[] args) {
int a=10;
int x;
 x= ++a + ++a;
System.out.println(x);
}
}

Output is 23. Need little help.

sha sha
  • 115
  • 8

1 Answers1

2

You can divide x= ++a + ++a; into 3 pieces.

Firstly, the first ++a will be done. Then the second ++a will be done. Then the + will be done.

So after the first ++a, a will be 11. After the second ++a, a will be 12. After the +, a will be 11 + 12 = 23.

khelwood
  • 52,115
  • 13
  • 74
  • 94
Anton Kolosok
  • 472
  • 6
  • 19