Created
September 21, 2022 16:32
-
-
Save sanikamal/40110a4ae6f8989b521aa6b5b73b76d0 to your computer and use it in GitHub Desktop.
Given an array, A, of N integers, print A's elements in reverse order as a single line of space-separated numbers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public static void print(String[] arr){ | |
for(int i = arr.length - 1; i >= 0; i--){ | |
System.out.print(arr[i] + " "); | |
} | |
} | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
int n = Integer.parseInt(in.nextLine()); | |
String[] arr = in.nextLine().split(" "); | |
in.close(); | |
print(arr); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input().strip()) | |
arr = list(map(int, input().rstrip().split())) | |
print(' '.join(str(i) for i in arr[::-1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment