• + 6 comments

    here is the code which worked for me. Hope it works for you as well...

    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]);
        }
    }
    

    }

    • + 1 comment

      Please dont share anything you want

      • + 2 comments

        here is Java 1D array problem solution https://programs.programmingoneonone.com/2021/02/hackerrank-java-1-d-array-solution.html

        • + 0 comments

          Here are my few different solutions in Java. 100% all test cases will pass

          I hope you will find my answer useful.

          Hackerrank Java 1D Array Solution

        • + 0 comments

          updated solution is here

          https://www.thecscience.com/2021/05/HackerRank-java-1D-array-problem-solution.html

    • + 0 comments

      thanks

    • + 2 comments

      can you tell me how's data is declaring in this two loops

      • 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]);*
      • + 0 comments

        for(int i = 0; i < n; i++){ a[i]=scan.nextInt(); } This piece of code takes input it doesn't print in order for something to be printed we need to use System.out. Therefore this piece of code only accepts input.

        for (int i = 0; i < a.length; i++) { System.out.println(a[i]); } This piece of code displays each element one by one as the value of i increases. Therefore it is only this loop that prints the values and hence only one loop displays the values.

      • + 0 comments

        In the first loop we are inserting the values to each ith indices of the array . In the second loop we are displaying the inserted values of the respectve ith indices starting from 0 to n.

        Here is my solution for better understanding https://www.codinghumans.xyz/2020/08/java-1d-array-hackerrank-solution-by.html

    • + 0 comments

      this code printing array element like this: 10 20 30 40 50 10 20 30 40 50

    • + 0 comments

      this code is giving wrong output..

    • + 0 comments

      i also did but my both test case failed