class Test {
public static void main(String[] args) {
int[] list = {1, 2, 3, 4, 5};
reverse(list);
for (int i = 0; i < list.length; i++) {
System.out.print(list[i] + " ");
}
}
public static void reverse(int[] list) {
int[] newList = new int[list.length];
for (int i = 0; i < list.length; i++) {
newList[i] = list[list.length - 1 - i];
}
list = newList;
}
}
当我运行这个程序时,答案是 1 2 3 4 5。这个“反向”方法在第 4 行被调用。