public class TestArgsTransfer {
public static void main(String[] args) {
TestArgsTransfer tt = new TestArgsTransfer();
int i = 10;
int j = 5;
System.out.println("i:" + i + " j:" + j);//i : 10 j : 5
tt.swap(i, j);
System.out.println("i:" + i + " j:" + j);//为啥交换后的值还是i : 10 j : 5
}
//定义一个方法,交换两个变量的值
public void swap(int i,int j){
int temp = i;
i = j;
j = temp;
System.out.println("i:" + i + " j:" + j);
}
}
|
|