public class 关于自加 {
public static void main(String[] args) {
int a = 1;
int b = 1;
int c = 1;
int d = 1;
a = b++;
/**
* 1. int temp = b //定义临时接收变量
* 2. b = b+1
* 3. 判断++在哪里
* 4. a = temp
*/
System.out.println(a + " " + b);// 1 2
a = ++b;
/**
* 1. int temp = b //定义临时接收变量
* 2. b = b+1
* 3. 判断++在哪里
* 4. a = b
*/
System.out.println(a + " " + b);// 3 3
c = ++c;
/**
* 1. int temp = c =1 //定义临时接收变量
* 2. c = c+1 =2
* 3. 判断++在哪里
* 4. c = c =2
*/
System.out.println(c);// 2
d = d++;
/**
* 1. int temp = d =1 //定义临时接收变量
* 2. d = d+1 =2
* 3. 判断++在哪里
* 4. d = d =1
*/
System.out.println(d);// 1
}
} |