simple menu base program java using while loop code example
Example 1: How to make a Java Main Menu Loop after using a case
int choiceentry;
do {
System.out.println("Enter \"1\", \"2\" or \"3\"");
choiceentry = scanchoice.nextInt();
switch (choiceentry)
{
case 1:
break;
case 2:
break;
case 3:
break;
default:
System.out.println("Choice must be a value between 1 and 3.");
}
} while (choiceentry != 3);
Example 2: How to make a Java Main Menu Loop after using a case
int choiceentry = -1
while(choiceentry < 1 || choiceentry > 3){
System.out.println("Enter \"1\", \"2\", \"3\" or \"4\"");
if(scanchoice.hasNextInt())
choiceentry = scanchoice.nextInt();
}
switch(choiceentry){
case 1:
break;
case 2:
break;
case 3:
break;
}