I've created this method for a validation when the user will type the option that appears on the screen:
private int menu;
private int menuImprimir;
public int getMenu()
{
return menu;
}
public void ativarStatus()
{
this.status = "Ativado";
}
public void menuImprimir()
{
System.out.println("Deseja Imprimir os dados?" +
"\n1 - Sim" +
"\n2 - Não");
this.menuImprimir = input.nextInt();
while(this.menuImprimir < 1 || this.menuImprimir > 2)
{
System.out.println("\nErro! - Digite uma opção válida");
menuImprimir();
}
switch(this.menuImprimir)
{
case 1:
imprimir();
break;
case 2:
System.out.println("Obrigado! ... ");
break;
default:
System.out.println("Opção inválida!\nDigite novamente: ");
break;
}
}
If the client types the option other than 0 and 1 it stays within the while asking him to enter the correct option. But if the client type 3 times the wrong option and in the fourth he type the correct one the system is printing System.out.println("Concluído com Sucesso!");
"3 times to later leave the method, even if I put this return ..