-
-
Save parzibyte/a133ed266f9c8be47386eff9717e89ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://parzibyte.me/blog | |
public static int solicitarNumeroValido(String mensaje, int minimo, int maximo) { | |
Scanner s = new Scanner(System.in); | |
int numero; | |
while (true) { | |
System.out.println(mensaje); | |
if (s.hasNextInt()) { | |
numero = s.nextInt(); | |
if (numero >= minimo && numero <= maximo) { | |
return numero; | |
} else { | |
System.out.println("Número fuera de rango. Intente de nuevo"); | |
} | |
} else { | |
s.next(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment