Hi there i want a basic menu which the user inputs a number to chose from the menu. Thing is that i need to make sure that the input IS an integer. So i have an InputMismatchEx ception catch but when it occurs, the program just keeps outputting the menu over and over??
[code=java]
static Scanner sc = new Scanner(System. in);
public static void menu (){
System.out.prin tln("Please enter a number to select from the following:\n\t1 . Create new Array\n\t2. Load array from MyObject.dat");
int choice = 0;
try{
choice = sc.nextInt();
switch(choice){
case 1:
start();
break;
case 2:
loadArray();
break;
default :
System.out.prin tln("invalid");
}
}catch (InputMismatchE xception e){
System.out.prin tln("Please enter a valid NUMBER from the menu... Resetting menu.");
}
menu();
}[/code]
[code=java]
static Scanner sc = new Scanner(System. in);
public static void menu (){
System.out.prin tln("Please enter a number to select from the following:\n\t1 . Create new Array\n\t2. Load array from MyObject.dat");
int choice = 0;
try{
choice = sc.nextInt();
switch(choice){
case 1:
start();
break;
case 2:
loadArray();
break;
default :
System.out.prin tln("invalid");
}
}catch (InputMismatchE xception e){
System.out.prin tln("Please enter a valid NUMBER from the menu... Resetting menu.");
}
menu();
}[/code]
Comment