我需要使用循环自动执行以下代码段。即使可用性点达到无穷大,我也需要获取最大值

我如何在几行代码中实现

if (availPoints < 500 ) {
   pointsMax = 500;
   MoneyMax = 25;
}
else if (availPoints < 1000 ) {
   pointsMax = 1000;
   MoneyMax = 50;
}
else if (availPoints < 1500 ) {
   pointsMax = 1500;
   MoneyMax = 75;
}


更新:

假设availPoint是用户得分从1到1000000(也是无限)的点。每500点是一个插槽。如果点进入下一个插槽。最大值pointMax必须增加500,MoneyMax必须增加25。

最佳答案

它不需要循环。

    for (int availPoints = 400; availPoints < 2000; availPoints += 200) {
        int rank = availPoints / 500;
        int pointsMax = (rank + 1) * 500;
        int MoneyMax = (rank + 1) * 25;
        System.out.printf("availPoints %d -> pointMax=%d MoneyMax=%d%n",
            availPoints, pointsMax, MoneyMax);
    }


结果:

availPoints 400 -> pointMax=500 MoneyMax=25
availPoints 600 -> pointMax=1000 MoneyMax=50
availPoints 800 -> pointMax=1000 MoneyMax=50
availPoints 1000 -> pointMax=1500 MoneyMax=75
availPoints 1200 -> pointMax=1500 MoneyMax=75
availPoints 1400 -> pointMax=1500 MoneyMax=75
availPoints 1600 -> pointMax=2000 MoneyMax=100
availPoints 1800 -> pointMax=2000 MoneyMax=100

10-08 02:18