标签:java ar sp c print public class as
java中方法的参数传递只有一种:值传递
public class SwapMethod {
/**
* 交换方法
* @param a
* @param b
*/
public static void Swap(int a , int b){
int temp ;
temp =a;
a = b;
b = temp;
System.out.println("交换后的a = "+a+"; b = "+b);
}
public static void main(String[] args){
int a = 1;
int b = 2;
Swap(a,b);
System.out.println("交换结束后 a = "+a+"; b = "+b);
}
}
输出结果: 交换后的 a = 2; b = 1
交换结束后 a = 1; b = 2
标签:java ar sp c print public class as
原文地址:http://www.cnblogs.com/viceren/p/3921467.html