Java - Array data structure

Task

Given an array, A, of N integers, print its elements in reverse order as a single line of space-separated numbers.

Demo

public class Main {
  public static void main(String[] args) {
    int n = 10;/*from w  w w  .  j a va  2 s.c om*/
    int[] arr = new int[n];
    for (int i = 0; i < n; i++) {
      arr[i] = i;
    }
    while (n > 0) {
      System.out.print(arr[--n] + " ");
    }
    System.out.println("");

  }
}

Related Topic