Saturday, September 6, 2025
HomeLanguagesJavaModulo or Remainder Operator in Java

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 %.

NOTE:    If numerator is less than denominator then % will give output as the numerator only.

Syntax:

A % B
Where A is the dividend and B is divisor

Example:

Input : a = 15, b = 6 
// 15%6 means when we divide 15(numerator) by 6(denominator) we get remainder 3// 
Output: 3
Input : a = 16, b = 4 
Output: 0

Approach:

  1. Take Dividend and Divisor from the user.
  2. Create an integer variable and assign it with A % B expression.
  3. Print that variable.

Below is the implementation of the above approach:

Java




// Implementation of Modulo or Remainder Operator in Java
import java.io.*;
import java.util.*;
 
class GFG {
    public static void main(String[] args)
    {
        // Dividend
        int a = 15;
 
        // Divisor
        int b = 8;
 
        // Mod
        int k = a % b;
        System.out.println(k);
    }
}


Output

7

Time Complexity : 

Modular function usually takes Constant time / O(1) time like other arithmetic operations.
 

RELATED ARTICLES

Most Popular

Dominic
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS