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. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution


download android app

Popular HackerRank Java Solutions








codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube