# Java BufferedReader To get multiple user inputs



## existsign44 (Jun 6, 2009)

I want to use BufferedReader to get multiple inputs from the user.
For example

What do You select from the list?

Input --> 2 7 8

You have selected 2, 7, 8.

How do I would I do this.


----------



## jamiemac2005 (Jul 5, 2007)

Hey and welcome to TSF, can you clarify why you want to do this?

And have you tried this yet? (If you have please post your code in

```
tags)

I've got a way to do this in my head so i'll get it down and compiled and post it once you've posted back =]

Cheers,
Jamey
```


----------



## systemErr (Apr 18, 2008)

Forget bufferedreader. Just use a command prompt window with args[]. You can get all the input you want, very easily too!

But your code would use something like this:

new BufferedReader(new InputStreamReader(System.in));


----------



## jamiemac2005 (Jul 5, 2007)

Dead Thread.

But just for the sake of it:

```
import java.io.*;

public class UserInputFromOneLine{
	public static void main(String[] args)**
		//output a menu, message, whatever
		System.out.println("Menu or whatever");
		//Output a message which suggests multiple input necessary
		System.out.print("Which choices would you like to select?: ");
		
		//Create the BufferedReader object...
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		//create a string to hold the user's input
		String choices = null;
		
		//get the user's input
		try{
			choices = br.readLine();
			//catch errors(vague method)
		} catch (IOException exc)**
			System.out.println("Error: Something went wrong...");
		}
		
		//set up a string to hold the inputs as an array:
		String[] choicesSplit = null;
		choicesSplit = choices.split(" ");
		//the array choicesSplit now contains the split choices... etc.
		
		//output a message(or post-process, just whatever you need to do)
		System.out.print("You chose: ");
		//output the choices
		for(String choice: choicesSplit)**
			//output the choice
			System.out.print(choice);
		}
		
	}
}
```
Cheers,
Jamey


----------

