程序在 main 中使用 while 循环菜单来请求用户命令:
public static void main(String[] args)throws Exception
{
Boolean meow = true;
while(meow)
{
System.out.println("\n 1. Show all records.\n"
+ " 2. Delete the current record.\n"
+ " 3. Change the first name in the current record.\n"
+ " 4. Change the last name in the current record.\n"
+ " 5. Add a new record.\n"
+ " 6. Change the phone number in the current record.\n"
+ " 7. Add a deposit to the current balance in the current record.\n"
+ " 8. Make a withdrawal from the current record if sufficient funds are available.\n"
+ " 9. Select a record from the record list to become the current record.\n"
+ " 10. Quit.\n");
System.out.println("Enter a command from the list above (q to quit): ");
answer = scan.nextLine();
cmd.command(answer);
if(answer.equalsIgnoreCase("10") || answer.equalsIgnoreCase("q"))
{
meow = false;
}
}
}
如果您选择的命令实际上都不是菜单上的命令,则会发生这种情况:
else
{
System.out.println("Illegal command");
System.out.println("Enter a command from the list above (q to quit): ");
answer = scan.nextLine();
command(answer);
}
每当我添加一个新人或使用任何需要我按回车键完成输入值的命令时,我都会得到 else 语句,然后是常规命令请求。
所以它看起来像:
Enter a command from the list above (q to quit):
Illegal command
Enter a command from the list above (q to quit):
当这件事发生时。
不会在这里发布我的完整代码,我害怕它,因为它太多了。取而代之的是它们的粘贴箱。
- 我的完整主要课程: http: //pastebin.com/rUuKtpXb
- 我的完整非主课:http: //pastebin.com/UE4H76Cd
有谁知道为什么会这样?