Day 7: Arrays Hackerrank Solution Java
For Explanation Check The Video:
Sample Input
4
1 4 3 2
Sample Output
2 3 4 1
Code:
import java.io.*;import java.math.*;import java.security.*;import java.text.*;import java.util.*;import java.util.concurrent.*;import java.util.regex.*;
public class Solution {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) { int n = scanner.nextInt(); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
int[] arr = new int[n];
String[] arrItems = scanner.nextLine().split(" "); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
for (int i = 0; i < n; i++) { int arrItem = Integer.parseInt(arrItems[i]); arr[i] = arrItem; } for(int i=n-1;i>=0;i--){//3,2,1,0 System.out.print(arr[i]+" ");//2 3 4 1 }
scanner.close(); }}
Comments
Post a Comment