StringuserIptNum,userIptPsw;Scannerkeyboard=newScanner(System.in);while(true){menu();if(keyboard.hasNextInt()){intoption=keyboard.nextInt();switch(option){case1:System.ou...
String userIptNum, userIptPsw;
Scanner keyboard = new Scanner(System.in);
while (true)
{
menu();
if (keyboard.hasNextInt())
{
int option = keyboard.nextInt();
switch (option)
{
case 1:
System.out.println("Please input your student Number: ");
userIptNum = keyboard.nextLine();
System.out.println("Please input your student Password: ");
userIptPsw = keyboard.nextLine();
case 2:
System.out.println("*** THE END ***");
return ;
default:
System.out.println("Unrecognized option!");
continue;
}
}
else
{
keyboard.next();
//continue;
}
}
問題在于執行的時候,電腦不會停下來等使用者輸入學号,然後再提示輸入密碼,而是把兩行全部顯示在螢幕上之後再提示你輸入!!!
怎麼搞的? 能人解釋下。
展開