I'm trying to get the user to input any number between 0 and 10 an unlimited amount of times until they want to stop. They stop by entering the value -1. So far i have been able to create what happens when they enter a correct value, but when they enter -1 (which is an invalid value in the while loop), the program knows that it's invalid. All I'm looking for is for the program to exclude -1 for the possible invalid input, and to make the program stop asking for more input. Here's my code so far:
int userInput=0;
System.out.println("Please enter numbers ranging from 0 to 10 (all inclusive).");
System.out.println("When you want to stop, type and enter -1.");
while (userInput <= 10 && userInput >= 0)
{
userInput=Integer.parseInt(br.readLine());
while (userInput > 10|| userInput < 0)
{
System.out.println("That number is not in between 0 and 10. Please enter a correct number.");
userInput=Integer.parseInt(br.readLine());
}
sum=sum+userInput;
freq++;
}
while (userInput == -1)
{
System.out.println("You have chosen to stop inputing numbers.");
}
Sorry for my limited understanding :/