gpt4 book ai didi

java - Android - 如何简化十的倍数?

转载 作者:行者123 更新时间:2023-12-02 01:48:03 27 4
gpt4 key购买 nike

我想要多个值,如下所示:

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的精确倍数。

关于java - Android - 如何简化十的倍数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53454790/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com