非常感谢您的回复,我可能会坚持只添加额外的input.nextLine()语句来捕获任何“残留”。在这段代码中,我输入了2,一旦它进入if语句,它跳过了“sCreateLogin = input.nextLine();”,并继续进行下一个输入。很可能是因为还有其他东西留在了Scanner中,但我无法弄清楚它为什么这样做以及如何修复它。如果我使用input.next(),它会停止,但这还不够好,因为如果您意外添加一个空格,它也会跳过下一个输入。我知道我可以解析它等等,但我仍然对此感到困惑。
Scanner input = new Scanner(System.in);
System.out.println("(1) Login");
System.out.println("(2) Create Account");
int iAccountOption = input.nextInt();
if(iAccountOption==2)
{
System.out.println("Input desired login: ");
String sCreateLogin = input.nextLine();
System.out.println("Input desired password: ");
String sCreatePassword = input.nextLine();
}