#while loop ignores a scan.nextLine first time it runs

9 messages · Page 1 of 1 (latest)

rocky turret
#

Hi, java beginner here.
I am making a small rock paper scissors game but I run into the problem that the while loop skips the playerChoice input scan (line 50) and the switch statement (starting line 55) every first time the loops runs. Does annyone see where I made a mistake or could point me at the right direction?

one thing I tried to narrow it down a bit more, I assigned a value to playerChoice so it would have a value even when skipped by the scan.nextLine, but still it is skipping the switch statement.

ionic citrusBOT
#

This post has been reserved for your question.

Hey @rocky turret! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

fallow kindle
#

Probably because you used scan.nextInt() beforehand.

#

This SO post sums the problem up nicer than I could:

#

TLDR: The nextint() method doesn't consume the backspace

rocky turret
#

That was indeed the problem, Thanks!

ionic citrusBOT
# rocky turret That was indeed the problem, Thanks!

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.