0
I’m trying to make a try
to ask for the option number for the user, but I want to do this until he type an integer number, I did a Try/catch, but when I run it and digit a string
it keeps sending an error message several times, and I can’t identify the error;
public class CaniveteSuico {
static Scanner in = new Scanner (System.in);
public Integer Menu() {
int opcao=0;
int checar=0;
do {
checar=0;
System.out.println("\n ==================================");
System.out.println(" | 1 - Gestão de Produtos |");
System.out.println(" | 2 - Gestão de Vendas |");
System.out.println(" | 3 - Gestão de Pessoas |");
System.out.println(" | 0 - Sair |");
System.out.println(" ===================================\n");
System.out.print(" Opção -> ");
try {
opcao = in.nextInt();
System.out.print("\n");
checar =1;
} catch(Exception e) {
System.err.println("Você digitou um caractere inválido! Tente novamente ");
}
} while(checar==0);
return opcao;
}
}
Thank you very much, solved my problem! Hug!!
– Pedro Augusto Null