Created
October 28, 2022 11:41
-
-
Save roopeshsn/0daf2610c9ebe8fd0d7d940363a03362 to your computer and use it in GitHub Desktop.
Code to get array input from command-line in Java
This file contains 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
package com.roopesh; | |
import java.util.Arrays; | |
public class Main { | |
public static void main(String[] args) { | |
int[] arr = getIntegerArray(); | |
System.out.println(Arrays.toString(arr)); | |
} | |
public static int[] getIntegerArray() { | |
Scanner scanner = new Scanner(System.in); | |
int size = scanner.nextInt(); | |
int[] arr = new int[size]; | |
for (int i = 0; i < size; ++i) { | |
arr[i] = scanner.nextInt(); | |
} | |
return arr; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment