可以使用以下方法实现Java数组的逆序输出数字:
int[] array = {1, 2, 3, 4, 5};
int[] reverseArray = new int[array.length];
for (int i = 0; i < array.length; i++) {
reverseArray[array.length - 1 - i] = array[i];
}
for (int i = 0; i < reverseArray.length; i++) {
System.out.println(reverseArray[i]);
}
完整代码如下所示:
public class ReverseArray {
public static void main(String[] args) {
int[] array = {1, 2, 3, 4, 5};
int[] reverseArray = new int[array.length];
for (int i = 0; i < array.length; i++) {
reverseArray[array.length - 1 - i] = array[i];
}
for (int i = 0; i < reverseArray.length; i++) {
System.out.println(reverseArray[i]);
}
}
}
运行以上代码,将会输出以下结果:
5
4
3
2
1