how to read space separated integers in java

Solutions on MaxInterview for how to read space separated integers in java by the best coders in the world

showing results for - "how to read space separated integers in java"
Aitana
07 Mar 2016
1String s[]= scanner.nextLine().split(" ");for(int i =0 ;i < s.length;i++){    a[i]= Integer.parseInt(s[i]);}
Serena
13 Jun 2016
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
Dario
27 Jun 2020
1import java.io.BufferedReader;
2import java.io.IOException;
3import java.io.InputStreamReader;
4
5class BufferedReaderTest
6{
7    public static void main(String[] args) throws IOException {
8        BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
9
10        int num[] = new int[1000];
11        String[] strNums;
12        long startTime, endTime;
13
14
15        /*________ TEST STARTS ________*/
16        startTime = System.nanoTime();
17        strNums = bi.readLine().split("\\s");
18        for(int i=0; i<strNums.length; i++) {
19            num[i] = Integer.parseInt(strNums[i]);
20        }
21        endTime = System.nanoTime();
22        /*________ TEST ENDS ________*/
23
24        System.out.println("Total Time Taken: " + (endTime - startTime));
25    }
26}
27
María Paula
27 Mar 2018
1# if you read from console
2
3	Scanner scanner = new Scanner(System.in);
4	List<Integer> list = new ArrayList<Integer>();
5	while (scanner.hasNextInt())
6  		list.add(scanner.nextInt());
7	int[] arr = list.toArray(new int[0]);
8
9# if you read from file
10
11	try {
12      	File myObj = new File("filename.txt");
13      	Scanner myReader = new Scanner(myObj);
14      	while (myReader.hasNextInt()) { // check for next integer in file
15        	String data = myReader.nextInt(); // read the integer
16        	System.out.println(data);
17      	}
18      	myReader.close();
19    } catch (FileNotFoundException e) {
20      	System.out.println("An error occurred.");
21      	e.printStackTrace();
22    }
queries leading to this page
how to read single ine space separated integer in javainput separated by space javahow to accept two integers separated by a delimiter in javataking space separated input in javajava input spereated by spaceprint numbers separated by space javaspace separated integers in javawhile loop to scan input separated with space in javahow to take integer inputs for java if they are given by delimites spaceshow can i take space seperated input in java 3fhow to read spaced integers in javahow to read two space separted input in javahow to read two space separated input in javahow do i take the input of two integers separated by whitespace in javahow to input space separated innteger in javamultiple integer input in javahow to take space seprated input in javaget a space input number javahow to take input separated with spaces in javahow to take input from user separated by spaces javaspace separated int string in javaspace separated integers sum in javahow to input when numbers are given in spaces in javahow to take input seperated with spaces in javahow to take two input separated by space in javaspace separated number input in javahow to take 2 space separated integer input in javahow to store two numbers seperated by space in two different array in javaspace separeted input javaa line containing two integers separated by a spacehow to get space separated input in javahow to take space separated input in havainput space separated integers in javahow to take multiple integer input in java using scannerinput two space separated integers in javaspace separated input for two different variable in javaspace seperated strings input in javataking space separated integers in javahow to take elements from space seperated string in javahow to take input in single line saperated by space in javagetting space separated input in javainput an array in java separate by spacereading space separated integers in javahow to take space separated input in array in javahow to input integers separated by whitespace in javatake input string and int with space in javahow to give space separated int input in javahow to read integer with space from input in javainput 2 numbers in a line in javatake space separated input string and int in java how to input a string of numbers seperated by a spacetwo space separated integers in javaspace sperarated input in jvahow to take input from user in java by space separatedspace seperated inpt in javatake space separated input in javaget integer input space seperated in javainput two space separated integers in javainteger split input in javajava integer separated by spacetake integr input seperated space in javahow to take no of inputs separated by space in javainputting m space seperated integers in jabvahow to take two space separated input in javahow to take a integer input and a char input seperated by space in javajava space separated inputscanning space separated array in javajava input separated by spacetaking 5 separate spaced integer input in javahow to add integers separated by space in javahow to take single line space separated input in javaprint space separated integers in javahow to take space separated string input in javahow to take space separated input in javjava space seperated value inputhow to accept space separated integers in javahow to read space separated integers in java using scannerhow to take input in java two space separated elementsspace separated integer input in javajava get input separated by spacetake space seperated input in javahow to take space separated input in java using scannertake two input separated by space in javahow to take input from user in java with space separatedhow to input 2 space separated integers in java in an arraytake input integer separated by space in javahow to get space separated string input in javahow to get integers separated by space in javahow to take space separated input in jvahow to input space separated integers in javahow to take space separated integer input in javahow to take space separated string ouput in javatake input separated by space in javaspace separated input in javainput n spaced in javahow to store two space seperated input to two different array in javaget input from user seperated by space javaprint number seperated by space javahow to takspace separated integers in javastore integers separated by spaces in javahow to get integers from a space separated stringcomma and space separated data from a text file javahow to read space separated integers in javahow to take array elements separated by space as an input in javahow to take 2 space separated integer input in java using scannerhow to take space separated input in javahow to get space seperated input in javahow to take space seperated string as input in javan space separated integers in javaspace separated string input in javahow to take input separated by space in javaaccept space seperated integeres and add to integer arrayhow to read space separated integers in java