Modulo or Remainder Operator in Java
Modulo or Remainder Operator returns the remainder of the two numbers after division. If you are provided with two numbers, say A and B, A is the dividend and B is the divisor, A mod B is there a remainder of the division of A and B. Modulo operator is an arithmetical operator which is denoted by %.
A % B Where A is the dividend and B is divisor
Input : a = 15, b = 6
// 15%6 means when we divide 15(numerator) by 6(denominator) we get remainder 3//
Input : a = 16, b = 4
- Take Dividend and Divisor from the user.
- Create an integer variable and assign it with A % B expression.
- Print that variable.
Below is the implementation of the above approach:
Time Complexity :
Modular function usually takes Constant time / O(1) time like other arithmetic operations.