<分区>
我正在学习 Java,据我了解,您需要指定函数返回的值。如果它不返回值,那么它就是无效的。 但是在下面的程序中,我可以通过 void 函数更改数组的值。谁能给我解释一下吗?
public class ArraysInMethods {
public static void main(String args[]){
int rd[] = {2,3,4,5,6};
change(rd);
for(int y: rd){
System.out.println(y);
}
}
public static void change(int x[]){
for(int counter = 0; counter<x.length;counter++){
x[counter]+=5;
}
}
}