on 01-12-2009 6:07 AM
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.......
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.