how to take space separated input in java

Solutions on MaxInterview for how to take space separated input in java by the best coders in the world

showing results for - "how to take space separated input in java"
Willis
08 Jun 2018
1String s[]= scanner.nextLine().split(" ");for(int i =0 ;i < s.length;i++){    a[i]= Integer.parseInt(s[i]);}
Liah
01 Sep 2020
1 Scanner scanner = new Scanner(System.in);
2 int numOfBlocks = scanner.nextInt();
3 int weightArray[] = new weightArray[numOfBlocks];
4 for(int i=0;i<numOfBlocks;i++)
5       {
6        weightArray[i] = scanner.nextInt();
7       }
8 scanner.close();
9//your logic
Mavis
22 Nov 2020
1import java.util.*;
2
3public class buffer 
4{
5	public static void main(String[] args) 
6	{
7		Scanner scan = new Scanner(System.in);
8		System.out.println();
9		int i;
10		 int a[]=new int[100];
11		 String s[]= scan.nextLine().split(" ");
12		for(i =0 ;i < s.length;i++){
13		 a[i]= Integer.parseInt(s[i]);
14		}
15		for(i =0 ;i < s.length;i++)
16		 System.out.println(a[i]);
17	}
18}