我是Java的新手。我编写了这个程序来反转数组:
public class Reverse {
public static void main(String[] args) {
int num[] = {55, 2, 37, 9, 8};
System.out.println("Original array is: ");
for (int i : num)
System.out.print(i + " ");
for (int i = 1 ; i != 5; i++) {
num[i - 1] = num[num.length - i];
}
System.out.println("\nReversed array is: ");
for (int i : num)
System.out.print(i + " ");
System.out.println(" ");
}
}
但我得到以下结果。你们知道我做错了什么吗?
原始数组为:55 2 37 9 8 反转数组为:8 9 37 9 8