我遇到问题,在用户回答是之后重复循环,这应该重复该程序,但它跳过正文并立即再次询问最后一个问题。
这是程序的一部分(当它要求怪物类时输入两栖动物):
public class MH4 {
public static void main(String[] args) {
String answer = "yes";
String monster, amphibian;
String s2 = "Water", s3 = "Thunder";
String b1 = "Head", b2 = "Front legs", b4 = "Hind legs";
String f3 = "Fatigue", i1 = "Ice Blight", i2 = "Severe Ice Blight";
Scanner keyboard = new Scanner(System.in);
while (answer.equalsIgnoreCase("yes")) {
System.out.println("Which monster class do you want to look up?");
monster = keyboard.nextLine();
if (monster.equalsIgnoreCase("Amphibian")){
System.out.println("\nThese are the monsters under that classification:\n");
System.out.println("Tetsucabra\nBerserk Tetsucabra\nZamite\nZamtrios\nTigerstripe Zamtiros");
System.out.println("\nWhich of these monsters would you like to gather information on?");
amphibian = keyboard.nextLine();
if (amphibian.equalsIgnoreCase("Tetsucabra"))
System.out.println("\nThis monster is weakest to: " + s2 + " and " + s3);
System.out.println("\nThis monster's weakest point is its: " + b1 + ", " + b2 + ", and " + b4);
System.out.println("\nThis monster can cause:\n" + f3 + "\n" + i1 + " *\n" + i2 + " *\n");
System.out.println("* Tetsucabra only inflicts these while in the frozen seaway");
System.out.println("\nImportant Notes:\n- Its tail becomes its weakest point while it is holding boulders.\n- The projectiles that it shoots drain stamina.");
}
else {
System.out.println("That monster class does not exist in this game.");
}
System.out.println("\nIs there another monster or monster class you wish to look up?");
answer = keyboard.next();
}
}
}
如果你能弄清楚错误,请告诉我,因为我不知道它可能是什么。