public class Swap{
public static void main(String args[]){
Integer x = 1;
Integer y = 2;
swap(x,y);
System.out.println("x=" + x + " y=" + y);
int a[] = {1,2};
swap(a);
System.out.println("a[0]=" + a[0] + " a[1]=" + a[1]);
}
public static void swap(Integer a,Integer b){ //不起作用
Integer temp = a;
a=b;
b=temp;
}
public static void swap(int[] a){ //起作用
int temp = a[0];
a[0] = a[1];
a[1] = temp;
}
}