• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scanner object question...  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm new to Java and I was wondering how you would detect if a user just hits "enter" at a prompt? I'm trying to give the user the option to terminate the input phase.

Thanks.
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

It depends on what methods you're using to get the input.

For example, Scanner's nextLine() method returns a String representing the "input that was skipped." If nothing other than Enter is pressed, then this will be an empty String ("").
 
Jose Imenes
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks very much.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!