Skip to content
Advertisement

How to read multiple integer values from one line in Java using BufferedReader object?

I am using BufferedReader class to read inputs in my Java program. I want to read inputs from a user who can enter multiple integer data in single line with space. I want to read all these data in an integer array.

Input format- the user first enters how many numbers he/she want to enter

And then multiple integer values in the next single line-

INPUT:

5

2 456 43 21 12

Now, I read input using an object (br) of BufferedReader

JavaScript

Next, I want to read next line inputs in an array

JavaScript

But we cannot read using this technique

JavaScript

So, is there any solution to my problem or we can’t just read multiple integers from one line using BufferedReader objects

Because using Scanner object we can read this type of input

JavaScript

Advertisement

Answer

Try the next:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement