我无法获得循环在代码中工作,所以如果用户说“否”,它会将他们带回第一个问题,他们必须回答“是”。如何获得循环工作
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