自增概念區分

一句話: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 
	}
    
    
    }






 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章