我無法獲得循環在代碼中工作,所以如果用戶說「否」,它會將他們帶回第一個問題,他們必須回答「是」。如何獲得循環工作
System.out.println("Adventurer soliders need your aid in Silverkeep can you deliver supplys to them? ");
String choice;
System.out.print("So can you deliver the supplys to them? ");
choice = in.next();
if (choice.equals("Yes"))
System.out.println("Thank you so much, he are the supplys they need.");
else if (choice.equals("No"))
System.out.println("But these soliders lives depend on these supplys! You must help us.");
因此,如果他們說不,它會將他們帶回到System.out.print行。
System.out.println("Adventurer soliders need your aid in Silverkeep can you deliver supplys to them? ");
while (run) {
String choice;
System.out.print("So can you deliver the supplys to them? ");
choice = in.next();
if (choice.equals("Yes"))
System.out.println("Thank you so much, he are the supplys they need.");
else if(choice.equals("No"))
System.out.println("But these soliders lives depend on these supplys! You must help us.");
run = true;
}
當我嘗試運行上面的代碼時,它只是用「所以你可以向他們提供耗材?」來控制檯。
那麼我哪裏去錯了..我嘗試了多種事情,但沒有運氣。
你如何 '在' 申報? –
'run = true;'總是如此。無限循環 –
不要在in.next – deviantfan