简体   繁体   English

如何从数字中获取下一个最高的九个间隔

[英]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 但是应该是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 . slot1++slot2slot1 (0),然后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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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