一句话:size++ 后于整体语句实行。
public class 前缀加加 {
static int m( int i){
return i++;
}
public static int getValue1(){
int i = 1;
try{
i = 4;
}finally{
i++;
}
return i;
}
public static int getValue2(){
int i = 1;
try{
i = 4;
}finally{
i++;
}
return i++;
}
public static int getValue3(){
int i = 1;
try{
i = 4;
}finally{
++i;
}
return ++i;
}
public static int getValue4(){
int i = 1;
try{
i = 4;
}finally{
++i;
}
return i;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("函数m:"+m(5)); //结果为 5
System.out.println("getValue():"+getValue1()); //结果为 5
System.out.println("getValue():"+getValue2()); //结果为 5
System.out.println("getValue():"+getValue3()); //结果为 6
System.out.println("getValue():"+getValue4()); //结果为 5
for(int i = 1;i <=5;i++){
System.out.println(i);
} //输出为
int size = 3;
while(size-->0){ //当size作为统计次数的时候只需要了解其能够运行多少次,不必
System.out.println("size:"+size);
}//输出为 2 1 0
System.out.println();
int size1 = 3;
while(size1>0){//当输出为3时候 进行下一次的比较此时的 size1为2 以此类推
System.out.println("size1:"+size1--);
} //输出为 3 2 1
System.out.println();
int size2 = 3;
while(--size2>0){
System.out.println("size2:"+size2);
}//输出为 2 1
}
}