Results 1 to 4 of 4
Thread: command to wait for user's input
- 04-28-2014, 02:40 AM #1
Member
- Join Date
- Apr 2014
- Posts
- 2
- Rep Power
- 0
- 04-28-2014, 09:35 AM #2
Senior Member
- Join Date
- Feb 2014
- Posts
- 447
- Rep Power
- 8
Re: command to wait for user's input
Hi,
You can read the System.in stream directly or use the Scanner class to get user input.
But Javas does not offer a getKey function, the Input of the user is available after the return key was pressed.
So with a Scanner instance you could call nextLine() after asking the user to press the Enter key.
Konrad
- 04-30-2014, 03:42 AM #3
Member
- Join Date
- Apr 2014
- Posts
- 2
- Rep Power
- 0
Re: command to wait for user's input
I implemented a solution using a string variable that accepts the user's input from the nextLine() method of the Scanner class, previously assigning an empty string "" to the string variable before the reading of the keyboard, then I compare the length of that variable and if the length is zero then the user pressed enter because the variable length remained the same before the reading. This condition evaluation is in a loop while evaluation until the value of the string variable is 0, and then it will exit the loop. Can you provide an example on how to use the System.in stream directly? Thank you.
- 04-30-2014, 11:06 AM #4
Senior Member
- Join Date
- Feb 2014
- Posts
- 447
- Rep Power
- 8
Re: command to wait for user's input
Hi,
I would recommend to read
Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)
There is even a chapter about I/O from console.
Similar Threads
-
Have java wait for user input
By kkid in forum AWT / SwingReplies: 3Last Post: 02-14-2013, 07:02 PM -
Why won't my action listener wait for user input?
By kkid in forum New To JavaReplies: 20Last Post: 02-06-2013, 09:27 PM -
User interaction command-line
By kkid in forum New To JavaReplies: 8Last Post: 10-29-2012, 02:37 PM -
Is there a way to wait for input from a button?
By KingOfClubs in forum NetworkingReplies: 4Last Post: 04-21-2011, 10:14 PM -
Why doesnt my code wait for input?
By Addez in forum New To JavaReplies: 7Last Post: 08-19-2009, 11:25 PM
Bookmarks