这是一道编程题
public class ArgsDemo {
public static void main(String[] args) {
int a = 10;
int b = 20;
change(a, b);
System.out.println(a + "---" + b); // 10---20这里输出的是10和20 为什么值不发生变化呢 谁能从原理上解释
int[] arr = { 1, 2, 3, 4, 5 };
change(arr);
for (int x = 0; x < arr.length; x++) {
System.out.println(arr[x]);// 2,4,6,8,10
}
String s1 = "hello";
String s2 = "world";
change(s1, s2);
System.out.println(s1 + "---" + s2);// hello---world
}
public static void change(String s1, String s2) {
s1 = "haha";
s2 = "hehe";
}
public static void change(int[] arr) {
for (int x = 0; x < arr.length; x++) {
arr[x] *= 2;
}
}
public static void change(int a, int b) {
a = b;
b = a + b;
}
}
|
|