Monday, January 13, 2003 05:07 AM
Because you just messed with i by re-setting it.
The comiler looks the statemen and evaluates it left to right. Then, executes it right to left. So, it evalutes i to 2, puts it in a register and holds it there. Now it executes the statement. Since it has already used i, it will increment it. Then, it sets i equal to the value it was evaluated to... which was 2.
If you do something like:
int i = 2;
int j = i++;
System.out.println(i); //Prints 3;
If you write tricky ambigous code, you will get ambiguous, unexpected results. This is te stuff they try to trick you on in the Cert.