HackerRank/JAVA

Java 1D Array

예쁜꽃이피었으면 2024. 1. 22. 17:21

https://www.hackerrank.com/challenges/java-1d-array-introduction/problem?isFullScreen=true

 

Java 1D Array | HackerRank

Get started with one-dimensional arrays.

www.hackerrank.com

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

 

 


 

 

반응형