Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • 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.
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!