Search code examples
javabukkit

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.


Solution

  • 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;