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..! Ingrese un Numero Positivo Distinto de Cero");
- System.out.println(mensaje);
- linea = valorIngresado.nextLine();
- numero = Integer.parseInt(linea);
- }
- break;
- } catch (Exception e) {
- System.out.println("''ERROR..! Ingrese un Numero Positivo''");
- }
- }
- 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<=2 && numero>=1)){
- System.out.println("Opcion Incorrecta");
- System.out.println(mensaje);
- linea = opcion.nextLine();
- numero = Integer.parseInt(linea);
- }
- break;
- } catch (Exception e) {
- System.out.println("''ERROR..! Ingrese un numero''");
- }
- }
- return numero;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment