Home >Java >javaTutorial >Java classic programming question--output an array in reverse order
Output an array in reverse order.
public class Example31 {
public static void main(String[] args) {
int[] a = { 9, 4, 6, 8, 3, 21, 16, 12 };
covertArray(a);
}
public static void covertArray(int[] a) {
System.out.print("The original array is: ");
for (int r : a) {
System.out.print(r + " ");
}
System.out.print("\nThe reverse order of the array is: ");
int i = a.length - 1; i >= 0; i--) {
System.out.print(a[i] + " ");
The above is the detailed content of Java classic programming question--output an array in reverse order. For more information, please follow other related articles on the PHP Chinese website!