public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
int edad;
boolean repetir = true;
while (repetir) {
System.out.println("introduce edad");
try {
edad = entrada.nextInt();
repetir = false;
} catch (InputMismatchException e) {
entrada.nextLine();//Si quito esta linea entra en un bucle infinito.. Por qué? No entiendo porque se pone este codigo
System.out.println("error");
}
}
}
Why is this code put in the catch? input.nextLine ();
Why does it go into an infinite loop if I remove it?