0
Need help
can't find what is my mistake https://code.sololearn.com/c5AJzKEszCf3/?ref=app
4 Antworten
+ 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
+ 1
why not use if() as while() is a loop
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);
}
}
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