基本上我需要這個while循環執行4次nextInt()在while循環有問題
它會要求用戶輸入,然後使用該輸入在嵌套的if語句。 (重複4次)
第一個提示會出現,我可以輸入一個輸入。
但之後它只是給了我一個錯誤。
並保持將錯誤指向「int userInput = scan.nextInt();」
我不知道什麼是錯的。有人可以指導我嗎?感謝
int count = 0;
while (count < 4) {
System.out.println(prompt1);
int userInput = scan.nextInt();
(some nested if statements here to do my task, they all have
count++ at the end)
}
** **什麼錯誤你好嗎?你在哪裏定義和初始化'scan'? –
在while循環之外初始化它 – Oxtis
我們可以看到該代碼嗎?同時發佈你正在獲取的整個錯誤/異常。 –