基本数据类型传递的是 值的副本
public static void main(String[] args) {
int m = 10;
int n = 20;
System.out.println("交换前 m = "+ m+", n = "+n);
//调用方法
swap(m, n);
System.out.println("交换后 m = "+ m+", n = "+n);
swap(m, n);
}
public static void swap(int m,int n){
int temp = m;
m = n;
n = temp;
System.out.println("交换中 m = "+ m+", n = "+n);
}
public static void main(String[] args) {
String[] arr = {"安琪拉","米莱迪","妲己"};
System.out.println("交换前:"+ arr[0]);//安琪拉
swap(arr);
System.out.println("交换后:"+ arr[0]);// 安琪拉 林志玲
}
private static void swap(String[] arr) {
arr[0]="林志玲";
System.out.println("交换中:"+ arr[0]);//林志玲
}
public static void main(String[] args) {
String[] arr = {"安琪拉","米莱迪","妲己"};
System.out.println("交换前:"+ arr[0]);//安琪拉
swap(arr);
System.out.println("交换后:"+ arr[0]);// 安琪拉 林志玲
}
private static void swap(String[] arr) {
arr = new String[]{"吴京"};
arr[0]="林志玲";
System.out.println("交换中:"+ arr[0]);//林志玲
}