java - Android - 如何简化十的倍数?
问题描述
我想要这样的多个值:
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。谢谢
解决方案
int j = 10;
for (int i = 1; i <= 20 ; i++) {
if (currentScore == j) {
editor.putInt("TOP_LEVEL", topLevel + 1);
editor.apply();
break;
}
j = j + 10;
}
推荐阅读
- javascript - Google Sheets API v4 分享
- javascript - 谷歌地图在javascript中放大和缩小两次
- opencl - 在 OpenCL 上,我们可以假设连续写入是原子的吗?
- php - Symfony,在运行时更改数据库
- c# - HTTP 错误 500.52 - URL 重写模块错误。名称属性
- python - 整数值之间的条件前向填充
- laravel - 无法在 laravel 上使用 swagger 生成文档
- mysql - 动态数据透视表列mysql
- reactjs - 在 Firefox 中反应输入失去焦点
- javascript - 在将数组元素转换为字符串时附加逗号