cancel
Showing results for 
Search instead for 
Did you mean: 

Taking input from the user

gill367
Active Contributor
0 Kudos

Hello everyone!

I am new to java programming.

and learning java through a book.

but i am facing a difficulty in taking input from the users.

The class that is mentioned in the book for taking input from the user (Scanner class) is not present in my JDK.

What is the alternative for taking the input from the user?

Could you please suggest on this.......

Accepted Solutions (1)

Accepted Solutions (1)

former_member192434
Active Contributor
0 Kudos

Hi

use this code. to take the input value

InputStreamReader inStream = new InputStreamReader(System.in);

BufferedReader stdin = new BufferedReader(inStream);

Once the stream is open, you can read one line at a time as follows:

String data = stdin.readLine();

You can extract each data element of the string (separated by white space) using the following:

String nextDataValue;

StringTokenizer tokenizer = new StringTokenizer(data);

while (tokenizer.hasMoreTokens())

{

nextDataValue = tokenizer.nextToken();

// do something with nextDataValue

}

thanks

Answers (0)