0

How to perform non-constant tasks within a while loop?

I am a beginner and I am trying to make a simple game where the user adds as many sets of two random numbers as they can within a given time frame. I have a while loop that counts down an integer X to zero. I want it so that as long as X > 0, I can give two random numbers, wait for a response, and repeat that process indefinitely until the timer is up. If I put the user.Input inside the while loop it will just repeat constantly and not actually let any input. How do I allow both timer and prompt to work?

18th Mar 2018, 4:26 PM
Tpnoll Noll
Tpnoll Noll - avatar
5 odpowiedzi
0
Are you saying your scanner only accepts input once?
18th Mar 2018, 4:30 PM
Jiren The Grey
Jiren The Grey - avatar
0
The scanner won’t accept any input because it is constantly trying to activate
18th Mar 2018, 4:31 PM
Tpnoll Noll
Tpnoll Noll - avatar
0
It should pause the program to receive input. Please describe how you implemented it & which method you used to get the input.
18th Mar 2018, 4:39 PM
Jiren The Grey
Jiren The Grey - avatar
0
Scanner response = new Scanner(System.in) int r = response.nextInt(); Then I see if r = x + y I put all of this directly inside the brackets of the while loop
18th Mar 2018, 4:47 PM
Tpnoll Noll
Tpnoll Noll - avatar
0
There really is no reason why it should not work, perhaps examine your loop condition.
18th Mar 2018, 5:03 PM
Jiren The Grey
Jiren The Grey - avatar