简体   繁体   中英

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

I've made a class that will require me to get the next highest interval of nine when I get a number. Here is my current code.

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

Opposing players is returning one. However when I run the code,

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

However it should be slot1 = 0 slot2 = 1 slot3 = 9

I've only tested this with opposing players returning one, but it shouldn't change anything.

slot1++ sets slot2 to slot1 (0), then icrements slot1 . You need this:

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

您可以使用它来获取下一个最高的九个间隔。

number + (9 - (number % 9))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM