Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scanner NoSuchElementException

 
Yon Wolf
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...I'm trying to write this Blackjack program that runs until the user runs out of money. So the game has to run multiple times. My problem is, the Scanner only works in the first loop and then throws an exception the second time (on int wager=scan.nextInt();)! How can I get the Scanner to contnue taking inputs? (incomplete program shown)



 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

You should generally call any of the "hasNextXYZ()" methods before getting the next element. Working through http://www.coderanch.com/how-to/java/UserInput would also be helpful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic