Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Modulo {
- public static int validarNumero(Scanner valorIngresado, String mensaje) {
- int numero;
- String linea;
- while (true) {
- try {
- System.out.println(mensaje);
- linea = valorIngresado.nextLine();
- numero = Integer.parseInt(linea);
- while(numero<=0){
- System.out.println("Error: Debe ingresar un numero mayor a 0...");
- System.out.println(mensaje);
- linea = valorIngresado.nextLine();
- numero = Integer.parseInt(linea);
- }
- break;
- } catch (Exception e) {
- System.out.println("Error: Debe ingresar un numero... ");
- }
- }
- return numero;
- }
- public static int elegirOpcion(Scanner opcion , String mensaje){
- int numero;
- String linea;
- while (true) {
- try {
- System.out.println(mensaje);
- linea = opcion.nextLine();
- numero = Integer.parseInt(linea);
- while(!(numero<=3 && numero>=1)){
- System.out.println("Seleccione una opcion valida.");
- System.out.println(mensaje);
- linea = opcion.nextLine();
- numero = Integer.parseInt(linea);
- }
- break;
- } catch (Exception e) {
- System.out.println("Error: Debe ingresar un numero... ");
- }
- }
- return numero;
- }
- public static boolean multiplo(int x) {
- boolean multiplo = true;
- if (x%7==0)
- multiplo = true;
- else
- multiplo = false;
- return multiplo;
- }
- public static boolean numPrimo(int x) {
- boolean primo = true;
- if (x == 1 || ((x % 2) == 0 && x > 2)) {
- primo = false;
- } else {
- for (int i = 2; i < (x / 2); i++) {
- if (x % i == 0) {
- primo = false;
- break;
- }
- }
- }
- return primo;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement