0

Input Monument infinity loop

System. out. println("Insert monument:") ; while(sc. hasNextInt()) { int1.add(sc.nextInt()); } This is part of my code. If example I enter 1 3 4 5 and press Enter the program does not give me an error but does not continue. Thanks.

27th Apr 2019, 10:56 AM
Silvio Petix
Silvio Petix - avatar
5 Answers
0
It shouldn't result in an infinite loop. What exactly isn't working there? Can you post the entire code? https://code.sololearn.com/ctVlm8xMQtXa/?ref=app
27th Apr 2019, 11:39 AM
{ 𝄋 ℒ 𝄋 }
{ 𝄋 ℒ 𝄋 } - avatar
0
Ok 10 minutes and I send the entire code. Thanks
27th Apr 2019, 11:41 AM
Silvio Petix
Silvio Petix - avatar
27th Apr 2019, 11:56 AM
Silvio Petix
Silvio Petix - avatar
0
If you rewrite the bad part I thank you.
27th Apr 2019, 11:57 AM
Silvio Petix
Silvio Petix - avatar
0
I've been considering only the part you referred to. And it appears that the problem is in the if condition (line 25-27). Considering only this snippet the while should result in true as long as the next token is an int. I personally don't see much utility in having an extra exit condition there, but then again I looked at the other parts of the code only briefly. https://code.sololearn.com/cvoHU0Ti9nh4/?ref=app
27th Apr 2019, 12:25 PM
{ 𝄋 ℒ 𝄋 }
{ 𝄋 ℒ 𝄋 } - avatar