Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created May 21, 2021 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/ccde478ea797d07d7e5cfab43b2b1fc3 to your computer and use it in GitHub Desktop.
Save parzibyte/ccde478ea797d07d7e5cfab43b2b1fc3 to your computer and use it in GitHub Desktop.
public static int solicitarNumeroValido(String mensaje, int minimo, int maximo) {
int numero;
while (true) {
System.out.println(mensaje);
if (sc.hasNextInt()) {
numero = sc.nextInt();
if (numero >= minimo && numero <= maximo) {
return numero;
} else {
System.out.println("Número fuera de rango. Intente de nuevo");
}
} else {
sc.next();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment