elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Mensajes
Páginas: [1]
1  Programación / Java / Re: Ayuda con esta funcion en: 8 Julio 2010, 22:11 pm
Hola a to@s, llevo un tiempo registrado aunque no suelo postear.
He modificado un poco tu codigo pero creo que funciona:

Código:
public static int pedir_entero(String s) {
        int aux = 0;
        boolean correct = false;
        Scanner stdin = new Scanner(System.in);
        while (correct == false) {
            try {
                System.out.print(s);
                aux = stdin.nextInt();
                correct = true;
            } catch (InputMismatchException e) {
                System.out.println("ERROR," + s);
                stdin.next();
            }
        }

        return aux;
    }

Y debci me parece que tu codigo no te lo vuelve a pedir si es erroneo.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines