In this HackerRank Java 1D Array problem, we need to read an integer from stdin and saves it to a variable. and reads n integers corresponding to a0, a1, ---- an-1 from stdin and saves each integer ai to a variable. and also attempts to print each element of an array of integers named a.

HackerRank Java 1D Array problem solution

HackerRank Java 1D Array problem solution

import java.util.*;

public class Solution {

    public static void main(String[] args) {
       
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();

int[] a = new int[n];
for(int i = 0; i<n; i++){
    a[i] = scan.nextInt();
}


        scan.close();

        // Prints each sequential element in array a
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
    }
}