Last active
May 14, 2021 14:33
-
-
Save abdulateef/d915b724d9a50107e9b1507848c3a375 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 hidden or 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
import java.util.Scanner; | |
public class Reverse{ | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
// System.out.println("Enter the size of the array"); | |
int n = input.nextInt(); | |
int[] arr = new int[n]; | |
// System.out.println("Enter array values"); | |
for(int i=0; i<n; i++){ | |
arr[i]=input.nextInt(); | |
} | |
// System.out.println("Enter reversed array"); | |
for(int i=(arr.length-1); i>=0; --i){ | |
System.out.print(arr[i]+ " "); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full code for this
import java.io.;
import java.util.Scanner;
import java.math.;
import java.security.;
import java.text.;
import java.util.;
import java.util.concurrent.;
import java.util.function.;
import java.util.regex.;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
}