What are the rules for modulus operation in Java?

The rule for the modulus operation in Java is:

  1. If both operands are integers, the result of the modulo operation is the remainder of the two operands divided.
  2. If one of the operands is a floating point number, the result of the modulo operation is obtained by converting the floating point number to an integer before performing the modulo operation.
  3. If the dividend is positive, then the sign of the quotient is the same as the dividend; if the dividend is negative, then the sign of the quotient is opposite to the dividend.
  4. If the divisor is 0, an ArithmeticException will be thrown.
bannerAds