Why do I put an invalid entry as asdf the code below goes into infinite loop?
After catching the exception and writing the message, should not it ask for another entry again?
import java.util.Scanner;
public class Leitura {
public static void main (String[] argumentos) {
int chute = -1, sorteado = 37;
Scanner scanner = new Scanner(System.in);
do {
System.out.println("Insira um número:");
try {
chute = scanner.nextInt();
} catch (Exception excecao) {
System.out.println("Lol, loop infinito? Sem pedir outra entrada novamente?");
System.out.println("O chute foi: " + chute + "\n");
}
} while (chute != sorteado);
}
}