public class 数 {
public static void main(String []args){
// int i=2;
// int k=8;
// if(k/i==0){
// System.out.println("能整除");
//
// }else{
// System.out.println("不能整除");
// }
int i=9 ;
// i=i--;
i--;
System.out.println(i);
}}
i=i--输出是9,i--输出就是8,谁敢告诉我?
public class Test { public static void main(String[] args) {
int i=9;
i = i--;
// System.out.println(i);
int b = 9;
b--;
// System.out.println(b);
}
}javap -c Test
Compiled from "Test.java"
public class Test extends java.lang.Object{
public Test();
Code:
0: aload_0
1: invokespecial #8; //Method java/lang/Object."<init>":()V
4: returnpublic static void main(java.lang.String[]);
Code:
0: bipush 9
2: istore_1
3: iload_1
4: iinc 1, -1
7: istore_1
8: bipush 9
10: istore_2
11: iinc 2, -1
14: return}第7条语句istore_1指令
istore
store int to local variable
覆盖了。
i=i--
相当于
int temp = i;//先把i--这个表达式的值赋给临时变量
i--;//i自减
i = temp;//再把表达式的值赋给i