Alexis-Coria

ModuloPunto4

Sep 13th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. import java.util.*;
  2. public class Modulo2 {
  3. public static int validarNumero(Scanner valorIngresado, String mensaje) {
  4. int numero;
  5. String linea;
  6. while (true) {
  7. try {
  8. System.out.println(mensaje);
  9. linea = valorIngresado.nextLine();
  10. numero = Integer.parseInt(linea);
  11. break;
  12. } catch (Exception e) {
  13. System.out.println("Error: Debe ingresar un numero... ");
  14. }
  15. }
  16. return numero;
  17. }
  18. public static int elegirOpcion(Scanner opcion , String mensaje){
  19. int numero;
  20. String linea;
  21. while (true) {
  22. try {
  23. System.out.println(mensaje);
  24. linea = opcion.nextLine();
  25. numero = Integer.parseInt(linea);
  26. while(!(numero<=3 && numero>=1)){
  27. System.out.println("Seleccione una opcion valida.");
  28. System.out.println(mensaje);
  29. linea = opcion.nextLine();
  30. numero = Integer.parseInt(linea);
  31. }
  32. break;
  33. } catch (Exception e) {
  34. System.out.println("Error: Debe ingresar un numero... ");
  35. }
  36. }
  37. return numero;
  38. }
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment