Java Day 7: Arrays



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



  1. import java.io.*;
  2. import java.math.*;
  3. import java.security.*;
  4. import java.text.*;
  5. import java.util.*;
  6. import java.util.concurrent.*;
  7. import java.util.regex.*;
  8. public class Solution {
  9. public static void main(String[] args) {
  10. Scanner in = new Scanner(System.in);
  11. int n = in.nextInt();
  12. int[] arr = new int[n];
  13. for (int i = 0; i < n; i++) {
  14. arr[i] = in.nextInt();
  15. }
  16. for (int i = 0; i < n; i++) {
  17. int idx = n - i - 1;
  18. System.out.print(arr[idx] + " ");
  19. }
  20. in.close();
  21. }
  22. }