View difference between Paste ID: UaSEjdE1 and 2NyG0YLB
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: Debe ingresar un numero mayor a 0...");
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: Debe ingresar un numero... ");
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<=3 && numero>=1)){
33
                    System.out.println("Seleccione una opcion valida.");
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: Debe ingresar un numero... ");
41
            }
42
        }
43
        return numero;
44
    }
45
    
46
    public static boolean multiplo(int x) {
47
		boolean multiplo = true;
48
		if (x%7==0)
49
			multiplo = true;
50
		else
51
			multiplo = false;
52
		return multiplo;
53
	}	
54
    
55
    public static boolean numPrimo(int x) {
56
        boolean primo = true;
57
        if (x == 1 || ((x % 2) == 0 && x > 2)) {
58
            primo = false;
59
 
60
        } else {
61
            for (int i = 2; i < (x / 2); i++) {
62
                if (x % i == 0) {
63
                    primo = false;
64
                    break;
65
                }
66
            }
67
        }
68
        return primo;
69
    }
70
    
71
    
72
}