I read line with
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
reader.readLine();
Example input is
Simple answer would be read integer inside the for
loop using nextInt()
method of scanner class.
Here is the implementation :
import java.util.Scanner;
public class DriverMain {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the size of an array: ");
int size = scanner.nextInt();
System.out.println("Enter array elements separated by single space.");
int[] numbers = new int[size];
for(int i=0;i