Possible Duplicate:
java operator ++ problem
public class A {
public static void main(String[] args) {
int nir = 5;
nir = nir++;
System.out.print(nir);
}
}
Why is the output 5 and not 6?
Please don’t tell me what to do in order to get 6.. obviously I am able to get to 6, it’s just that the syntax looks fine to me and an explanation about what wrong with that will do better, thanks.
Because the expression
nir++evaluates to the old value ofnir. Soexp(nir++)is equivalent to:In your case that means:
Which of course makes no sense because it basically does nothing.