This code is some code that I started out with experimenting, from a bit of code that I
found in OCA Java SE 7 Certification Guide by Mala Gupta. What puzzles me is the
output. My question is why the difference? All of the variables that are used in the
two expressions are the SAME VALUE. I am using Eclipse for my IDE, but I tried it on
the command line and got the same results. Is it a bug?
int a = 0; int b = 0; int c = 0; int d = 0; int e = 0; int f = 0; a = 10; f = a++ + a + a-- - a-- + ++a; System.out.println("out " + f); a = 10; b = 10; c = 10; d = 10; e = 10; f = 0; f = a++ + b + c-- - d-- + ++e; System.out.println("out " + f); // Yes, the two are set up the same! f = a++ + b + c-- - d-- + ++e; f = a++ + a + a-- - a-- + ++a;
The result is:
out 32
out 31
????
Ok, so I just simplified it . . .
int a = 0; int b = 0; int f = 0; a = 10; f = a++ + a; System.out.println("out " + f); a = 10; b = 10; f = 0; f = a++ + b; System.out.println("out " + f);
Result:
out 21
out 20
It has got to be a bug . . . .