このフォーラムを使用するのはこれが初めてであり、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.");
}
}
}