I'm stuck.
I want the user to press enter key to proceed, but I don't know how to detect enter key press.
please help.
For further actions, you may consider blocking this person and/or reporting abuse
I'm stuck.
I want the user to press enter key to proceed, but I don't know how to detect enter key press.
please help.
For further actions, you may consider blocking this person and/or reporting abuse
Scofield Idehen -
Mike Young -
felix kagecha -
Sospeter Mong'are -
Top comments (1)
I'm assuming you mean in a console application.... You can use a
Scanner
. ThehasNextLine
method will return true if they enter anything. You can follow that with a call tonextLine
which will remove that line from the input stream and return it to you. If you literally only want to proceed if they pressed only the enter key and nothing else then you can check if the string returned is the empty string.Note that the
hasNextLine
will never return false if Scanner reading fromSystem.in
. It will wait for input and then return true.