I am trying to make a method that controls that the limit is between 0 and 100 and I want to control it through a while loop, but it does not work well for me.
public static int leerLimite(String mensaje){
//Variable
int limite = leerEntero(mensaje);
while (limite > 0 && limite < 100) {
limite = leerEntero(mensaje);
}
return limite;
}
The method that I call read integer works perfectly for me, with that method I only make sure that it is numeric and the parameter that I pass to it is the message I want the user to see.
I think the logical condition is wrong, the other option that it evaluates is to introduce two while loops, one to control that it is greater than or equal to 0 and another to control that it is less than or equal to 100.
I understand that what you want to do is to ask you for the number while the value is outside the range of 0 to 100.
If so, you are applying the while conditions backwards, you would have to do it like this:
So it will ask you while the value is less than 0 or greater than 100, so it will return a number between 0 and 100.