how to read space separated integers in java

String s[]= scanner.nextLine().split(" ");for(int i =0 ;i < s.length;i++){    a[i]= Integer.parseInt(s[i]);}

4.25
4
Chiwda 105 points

                                    # if you read from console

	Scanner scanner = new Scanner(System.in);
	List&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
	while (scanner.hasNextInt())
  		list.add(scanner.nextInt());
	int[] arr = list.toArray(new int[0]);

# if you read from file

	try {
      	File myObj = new File(&quot;filename.txt&quot;);
      	Scanner myReader = new Scanner(myObj);
      	while (myReader.hasNextInt()) { // check for next integer in file
        	String data = myReader.nextInt(); // read the integer
        	System.out.println(data);
      	}
      	myReader.close();
    } catch (FileNotFoundException e) {
      	System.out.println(&quot;An error occurred.&quot;);
      	e.printStackTrace();
    }

4.25 (4 Votes)
0
4.22
9
RLOA 65 points

                                    import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class BufferedReaderTest
{
    public static void main(String[] args) throws IOException {
        BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));

        int num[] = new int[1000];
        String[] strNums;
        long startTime, endTime;


        /*________ TEST STARTS ________*/
        startTime = System.nanoTime();
        strNums = bi.readLine().split(&quot;\\s&quot;);
        for(int i=0; i&lt;strNums.length; i++) {
            num[i] = Integer.parseInt(strNums[i]);
        }
        endTime = System.nanoTime();
        /*________ TEST ENDS ________*/

        System.out.println(&quot;Total Time Taken: &quot; + (endTime - startTime));
    }
}

4.22 (9 Votes)
0
3
1

                                     Scanner scanner = new Scanner(System.in);
 int numOfBlocks = scanner.nextInt();
 int weightArray[] = new weightArray[numOfBlocks];
 for(int i=0;i&lt;numOfBlocks;i++)
       {
        weightArray[i] = scanner.nextInt();
       }
 scanner.close();
//your logic

3 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how can I take space seperated input in java? space separated string input in java java integer separated by space getting space separated input in java how to read space separated integers in java using scanner how to take space separated input in hava how to take input in java two space separated elements input separated by space java how to take input from user separated by spaces java take input separated by space in java reading space separated integers in java how to take two space separated input in java java get input separated by space how to get integers separated by space in java n space separated integers in java how to input integers separated by whitespace in java take integr input seperated space in java space separated input for two different variable in java get integer input space seperated in java how to take space separated input in jav how to take space separated input in jva how to take space seperated string as input in java how to take input separated by space in java get input from user seperated by space java how to take input from user in java with space separated java input separated by space input space separated integers in java taking space separated input in java java space seperated value input how to take no of inputs separated by space in java input an array in java separate by space space sperarated input in jva how to store two numbers seperated by space in two different array in java how to store two space seperated input to two different array in java get a space input number java space separated number input in java how to take input separated with spaces in java how to take input seperated with spaces in java comma and space separated data from a text file java how to take single line space separated input in java print space separated integers in java print numbers separated by space java print number seperated by space java how to read two space separted input in java how to read two space separated input in java taking 5 separate spaced integer input in java java space separated input how to accept two integers separated by a delimiter in java how to take input from user in java by space separated integer split input in java how to take input in single line saperated by space in java how to read spaced integers in java how to give space separated int input in java how to take array elements separated by space as an input in java store integers separated by spaces in java how to add integers separated by space in java how to read integer with space from input in java A line containing two integers separated by a space inputting m space seperated integers in jabva space seperated inpt in java space separated integer input in java How to get space seperated input in java how to get integers from a space separated string how to read space separated integers in java scanning space separated array in java how to take multiple integer input in java using scanner how to take space separated integer input in java HOW TO TAKspace separated integers in java space separated integers in java how to take two input separated by space in java how to take elements from space seperated string in java take two input separated by space in java take space seperated input in java how to take space separated input in java how to take a integer input and a char input seperated by space in java multiple integer input in java how to accept space separated integers in java how to take integer inputs for java if they are given by delimites spaces how do i take the input of two integers separated by whitespace in java input two space separated integers in java space separated input in java how to take space separated input in java using scanner how to input when numbers are given in spaces in java how to input space separated innteger in java how to take 2 space separated integer input in java using scanner how to take 2 space separated integer input in java how to input 2 space separated integers in jAVA in an array take space separated input in java how to input space separated integers in java while loop to scan input separated with space in java java input spereated by space accept space seperated integeres and add to integer array take space separated input string and int in java take input string and int with space in java how to get space separated input in java input 2 numbers in a line in java how to take space separated input in array in java taking space separated integers in java input n spaced in java how to input a string of numbers seperated by a space
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source