当我遇到错误时,我正在制作我正在制作的游戏。我的 if/else if 语句直接跳到 else if 语句,即使它不应该。
String neededCredits = "200";
if(Peeamnt.getText() == neededCredits) {
System.out.println("You can afford this");
JOptionPane.showMessageDialog(BuyPoopButton,
"You have unlocked the Poop Button for 200 Pee Credits!",
"Toilet Master",
JOptionPane.WARNING_MESSAGE);
}
else if((!(Peeamnt.getText() == neededCredits))) {
System.out.println("You cannot afford this");
JOptionPane.showMessageDialog(BuyPoopButton,
"You do not have enough Credits to buy this!\n"
+ "To buy it, you need 200 Pee Credits!",
"Toilet Master",
JOptionPane.ERROR_MESSAGE);
}
即使 Peeamnt 的文本是偶数 200,代码也会跳转到 else if 语句,告诉我我没有 200 Pee Credits。(我正在制作的游戏包含很多厕所幽默。)无论如何,如果有人看到我在这段代码中的错误,请告诉我。如果您需要更多代码,请告诉我。