1

I'm writing a program that takes the mod of a integer and proceeds to do some further math, but for some reason it's not registering negative numbers in the mod operator.

For example:

Let's say the test class inputs n = -90

public static double mod(int n) {
    double mod = (n % 360) * Math.PI / 180;
    return mod;
}

The actual (n % 360) is returning -90 instead of 270 and I can't figure out why.

However my code works for positive numbers.

ex8
  • 97
  • 1
  • 7

0 Answers0