如何从数字中获得下一个最高的九个区间

How to get the next highest interval of nine from a number

我做了一个class,当我得到一个数字时,它会要求我得到下一个最高的间隔九。这是我当前的代码。

int slot1 = (int) Math.floor(opposingPlayers/9.0);
int slot2 = slot1++;
int slot3 = slot2*9;

对方玩家正在回击。但是当我 运行 代码时,

slot1 is equal to 1 
slot2 is equal to 0 
slot3 is equal to 0

不过应该是slot1 = 0 slot2 = 1 slot3 = 9

我只在对方玩家回传一个的情况下对此进行了测试,但它应该不会改变任何东西。

slot1++slot2 设置为 slot1 (0),然后递增 slot1。你需要这个:

int slot1 = (int) Math.floor(opposingPlayers/9.0);
int slot2 = slot1 + 1;
int slot3 = slot2*9;

您可以使用它来获得下一个最高间隔 9。

number + (9 - (number % 9))