0

trouble with code

https://code.sololearn.com/c8hFdWcTtM9s/#java again this works fine in eclipse here the while loop that should test if user entered wrong number and repeats user input doesnt work, can someone help with that?? When right numbers are entered program works just fine. In this version i simplified the code a bit so if i want i can add more choices, that was a suggestion from a member on earlier discussion on my previous code Any feedback is highly appreciated! thanks in advance

26th Jun 2017, 6:43 PM
Drazen Jankovic
Drazen Jankovic - avatar
3 Respuestas
+ 1
well for the first You're creating two same Scanner objects which is not good. But for me I don't think your while loop usage is too good. For Your goal You should use exceptions or one while loop with boolean variable. 4 example while(game){ if(=1)... If(=2)... if(=3)... else{... wrong number} }
26th Jun 2017, 8:18 PM
zdena
+ 1
The problem is that sololearn wants the input at the start, so you cannot check whether it's the right number and if not, and then ask for a new input.
27th Jun 2017, 6:15 AM
Jonas Schröter
Jonas Schröter - avatar
0
that while loop works in eclipse, it repeats the question until it gets the right numbers that is why im confused, i get it that keyboard variable is already declared as Scanner type same as pick is already declared as int, in eclipse when i remover Scanner and in in two lines in while loop it works, here it doesnt. also if i use the exaple you suggested i would reach program end without playing a game if the pick is wrong cuz i cant figure out how to restart it after every execution
26th Jun 2017, 8:32 PM
Drazen Jankovic
Drazen Jankovic - avatar