I am trying to write a method rollDice(int number, int nSides) which returns the total result of rolling the number dice with nSides sides.
So for example rollDice(3
When you use % on a negative number you get a negative number.
%
In this case the solution is simple, use
int roll = r.nextInt(nSides) + 1; // 1 to nSizes num += roll;