这是我第一次使用这个论坛,我对整个 Java 体验还是新手,如果这是一个非常简单的修复,请原谅我。
我正在尝试为学校制作这个项目,但我的 if else 语句无法正常工作。如您所见,如果您进入近战或远程,一切都很好,但如果您不这样做,它会重定向您。我的问题是,即使您键入 melee 或 ranged,它也会首先将您定向到 if 方法,然后立即将您重定向到 else 语句。
有谁知道我该如何解决这个问题?
newchamp.Type = JOptionPane.showInputDialog(null, "What type of champion have you summoned? (melee or ranged)", "Type", JOptionPane.PLAIN_MESSAGE);
if (Type.equalsIgnoreCase("melee")) {
JOptionPane.showMessageDialog(null,"You have now confirmed your champion, you can not edit anything from this point on.");
}
if (Type.equalsIgnoreCase("ranged")) {
JOptionPane.showMessageDialog(null,"You have now confirmed your champion, you can not edit anything from this point on.");
}
else {
JOptionPane.showMessageDialog(null,"You can only choose Melee or Ranged!");
newchamp.Type = JOptionPane.showInputDialog(null, "What type of champion have you summoned? (Melee or Ranged)", "Type", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null,"You have now confirmed your champion, you can not edit anything from this point on.");
}
}
}