[英]How to get the next highest interval of nine from a number
我上了一堂課,要求我得到數字時要獲得下一個最高的九分間隔。 這是我當前的代碼。
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),然后icrements slot1
。 你需要這個:
int slot1 = (int) Math.floor(opposingPlayers/9.0);
int slot2 = slot1 + 1;
int slot3 = slot2*9;
您可以使用它來獲取下一個最高的九個間隔。
number + (9 - (number % 9))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.