如果else语句与它应该做的相反! Java的

时间:2014-02-19 21:22:56

标签: java if-statement

Java问题我相信有一个快速解决方法:

public void setFlappyBirdHighScore(int newFlappyBirdHighScore) {
    if(newFlappyBirdHighScore > 999 || newFlappyBirdHighScore != 999) 
    {
        if(newFlappyBirdHighScore == flappyBirdHighScore) {
            System.out.println("The new score is the same as the old high score, please enter yor new high score");
        }
        else {
            flappyBirdHighScore = newFlappyBirdHighScore;
            System.out.println("Your new FlappyBird High Score is: " +newFlappyBirdHighScore);
        }
    }
    else {
        System.out.println("You have to many digits in your score, please use 1-3 digits.");
    }
} 

现在它在小于或999时打印最后一个else语句,但我希望它反过来说。如果输入的数字高于999我希望它打印最后一个语句,其他两个工作正常。除了这个小问题,还有什么快速的解决方案?

1 个答案:

答案 0 :(得分:0)

你的问题在这里:

if(newFlappyBirdHighScore > 999 || newFlappyBirdHighScore != 999)

你所说的是除非得分等于999,否则做最后的其他陈述。

你有更多的运气:

 if(newFlappyBirdHighScore <= 999)