Home  >  Article  >  Java  >  Java classic programming question--output an array in reverse order

Java classic programming question--output an array in reverse order

零下一度
零下一度Original
2017-06-25 10:36:137897browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn