View difference between Paste ID: qYKUMfg8 and 9JCFw0rY
SHOW: | | - or go back to the newest paste.
1
import java.util.*;
2
public class Modulo {
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
                while(numero<=0){
12
                    System.out.println("''ERROR..! Ingrese un Numero Positivo Distinto de Cero");
13
                    System.out.println(mensaje);
14
                    linea = valorIngresado.nextLine();
15
                    numero = Integer.parseInt(linea);
16
                }
17
                break;
18
            } catch (Exception e) {
19
                System.out.println("''ERROR..! Ingrese un Numero Positivo''");
20
            }
21
        }
22
        return numero;
23
    }
24
    public static int elegirOpcion(Scanner opcion , String mensaje){
25
        int numero;
26
        String linea;
27
        while (true) {
28
            try {
29
                System.out.println(mensaje);
30
                linea = opcion.nextLine();
31
                numero = Integer.parseInt(linea);
32
                while(!(numero<=2 && numero>=1)){
33
                    System.out.println("Opcion Incorrecta");
34
                    System.out.println(mensaje);
35
                    linea = opcion.nextLine();
36
                    numero = Integer.parseInt(linea);
37
                }
38
                break;
39
            } catch (Exception e) {
40
                System.out.println("''ERROR..! Ingrese un numero''");
41
            }
42
        }
43
        return numero;
44
    }
45
}