0

Need help

can't find what is my mistake https://code.sololearn.com/c5AJzKEszCf3/?ref=app

3rd Jul 2017, 9:06 PM
Yehuda
Yehuda - avatar
4 Respuestas
+ 2
I fixed your code but it creates an infinite loop when entering a number greater than 2 or less than 0. This should only happen on Sololearns code playground but on PC it should keep asking for input until you enter a number greater than 0 but less than 2. Figure out the fix.. https://code.sololearn.com/c5d53qbST72X/?ref=app
3rd Jul 2017, 9:14 PM
Ghauth Christians
Ghauth Christians - avatar
+ 1
why not use if() as while() is a loop
3rd Jul 2017, 9:49 PM
D_Stark
D_Stark - avatar
0
This will probably produce the results you're looking for: import java.util.Scanner; public class Program { public static void main(String[] args){ Scanner s = new Scanner(System.in); int numberEntered; do { System.out.println("Please enter the row number (0-2) "); numberEntered = s.nextInt(); } while ((numberEntered < 0) || (numberEntered > 2)); System.out.println(numberEntered); } }
3rd Jul 2017, 11:50 PM
ChaoticDawg
ChaoticDawg - avatar
0
Maybe this code can help you. used if else instead of while loop. the number would not be displayed if it is not between 0 and 2 but would be displayed if it is in the range. https://code.sololearn.com/csS82irRjfMr/?ref=app
4th Jul 2017, 1:09 AM
akriti more
akriti more - avatar