What are the rules for modulus operation in Java?
The rule for the modulus operation in Java is:
- If both operands are integers, the result of the modulo operation is the remainder of the two operands divided.
- 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.
- 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.
- If the divisor is 0, an ArithmeticException will be thrown.