public class MyTest {
public static int c =1;
public static int d = 2;
public static void main(String[] args) {
System.out.print("交换前\ta=" + c + "\tb=" + d + "\r");
Swap(c, d);
System.out.print("交换后\ta=" + c + "\tb=" + d + "\r");
}
// 交换a,b两个变量的值
public static void Swap(int c, int d) {
int temp = c;
c = d;
d = temp;
System.out.print("方法内\ta=" + c + "\tb=" + d + "\r");
}
}
结果:
交换前 a=1 b=2
方法内 a=2 b=1
交换后 a=1 b=2
为什么ab的值不变,怎么才能改变ab呢?不是标记为静态存储了吗