chessking1 - 1 year ago 101

Java Question

I have written a method variation:

`private int variation() {`

int randomNumber = randomGenerator.nextInt(90);

return (randomNumber + handicap)/18 - 2;

}

Assuming that the handicap is = 18, what are the minimum and maximum values that this method can return?

Answer Source

```
Maximum=3;
Minimum=-1.
```

From the docs for random

Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive)

Therefore, the maximum returnable value of nextInt(90) is 89 and the minimum is 0.

Plugging into your function: (89 + 18)/18 - 2 = (Technically 3.94444444444 which is rounded down to 3) (0+18)/18-1=-1