这不是一个重大问题,但我不明白为什么会发生这种情况,所以我想在这里发布一下。这是我的代码:
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);
这段代码本来运行良好,但有一个问题。错误信息请确保输入的是数字有时会在菜单后面显示,有时会在前面显示,有时甚至会在菜单中间显示。以下是程序的输出结果:
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
如果这有关系的话,我正在使用Eclipse。 我知道这不是一个大问题,但我很好奇为什么会发生这种情况。