public class IncrementalDemo {
public static void main(String[] args) {
int a = 1;
int b = 1;
int x = ++a;
int y = b++;
// ++a: Increase a, then use the value
// So x = ++a: a = a + 1, x = a
System.out.println("a = " + a + ", x = " + x);
// b++: Use the value, then increase b
// So y = b, b = b + 1
System.out.println("b = " + b + ", y = " + y);
}
}
a = 2, x = 2
b = 2, y = 1
网友评论