1. 程式人生 > >java——引用型別引數傳遞

java——引用型別引數傳遞

// 引用型別引數
public class test1
{
	int num = 1;
	public static void main(String[] args)
	{	
		int[] arr = new int[]{19, 30};
		System.out.print("change_pre  arr =");
		for (int i = 0; i < arr.length; i++) {  
		   System.out.print(arr[i] + ", ");  
		}  
		System.out.println();
		change(arr);
		System.out.print("change_after  arr =");
		for (int i = 0; i < arr.length; i++) {  
		   System.out.print(arr[i] + ", ");  
		}   
	}
	static void change(int[] tmpArr){
		
		System.out.print("in_change_pre  arr =");
		 for (int i = 0; i < tmpArr.length; i++) {  
		   System.out.print(tmpArr[i] + ", ");  
		} 
		System.out.println();
		int tmp = tmpArr[0];
		tmpArr[0] = tmpArr[1];
		tmpArr[1] = tmp;
		System.out.print("in_change_pre  arr =");
		for (int i = 0; i < tmpArr.length; i++) {  
		   System.out.print(tmpArr[i] + ", ");  
		}
		System.out.println();
		
	}
	
}