我想要多个这样的值:

if (currentScore == 10 | currentScore == 20 | currentScore == 30 | currentScore == 40 | currentScore == 50 | currentScore == 60
            | currentScore == 70 | currentScore == 80 | currentScore == 90 | currentScore == 100 | currentScore == 110
            | currentScore == 120 | currentScore == 130 | currentScore == 140 | currentScore == 150 | currentScore == 160
            | currentScore == 170 | currentScore == 180 | currentScore == 190 | currentScore == 200) {
        editor.putInt("TOP_LEVEL", topLevel + 1);
        editor.apply();
    }


如何简化该代码,因此可以计算许多currentScore。
谢谢

最佳答案

使用Java % operator

if (currentScore % 10 == 0) {
    editor.putInt("TOP_LEVEL", topLevel + 1);
    editor.apply();
}


%运算符返回余数。如果“ currentScore”除以10的余数为0,则意味着currentScore是10的整数倍。

10-05 18:25