This isn't a major issue, but I don't understand why this happens, so I figured I'd post it here. This is my code:
do{
printMenu();//method to print menu
try{
user=input.nextInt();
}
catch(InputMismatchException imme)
{
System.err.println("Make sure to enter a number.");
input.next();
continue;
}
switchMenu(user);//method with switch method for user input
}while(1<2);
The code runs fine except for one thing. The error message Make sure to enter a number. sometimes displays after the menu, sometimes before, sometimes in the middle of the menu. This is the output of the program:
1. Book a ticket
2. Cancel a ticket
3. Check how many seats left
4. Print seat map
5. Check price
6. Print ticket
7. Exit
a
1. Book a ticket
2. Cancel a ticket
3. Check how many seats left
4. Print seat map
5. Check price
6. Print ticket
7. Exit
Make sure to enter a number.//Error message after menu
asd//wrong input
Make sure to enter a number.//now error message displays before menu
1. Book a ticket
2. Cancel a ticket
3. Check how many seats left
4. Print seat map
5. Check price
6. Print ticket
7. Exit
asd
1. Book a ticket
2. Cancel a ticket
3. Check how many seats left
Make sure to enter a number.//in the middle now???
4. Print seat map
5. Check price
6. Print ticket
7. Exit
I am using Eclipse if it matters. I know it's not a big problem, but I'm curious why this happens.