Java/J2EE and SOA (349 Blogs) Become a Certified Professional
AWS Global Infrastructure

Programming & Frameworks

Topics Covered
  • C Programming and Data Structures (16 Blogs)
  • Comprehensive Java Course (4 Blogs)
  • Java/J2EE and SOA (346 Blogs)
  • Spring Framework (8 Blogs)

What is Modulus in Java and how does it work?

Last updated on Mar 01,2023 148.3K Views

24 / 72 Blog from Java Core Concepts

I am sure you would be familiar with the term Modulus. It is also one of the most commonly asked interview questions for C, C++, Java or Python. In this article, I am going to brush up the definition of modulus to you followed by the implementation process through Java.

Have a look at the agenda of this article:

Let’s begin!

What is a Modulus operator in Java?

The modulus operator returns the remainder of the two numbers after division. If you are provided with two numbers, say, X and Y, X is the dividend and Y is the divisor, X mod Y is there a remainder of the division of X by Y.

Let me make you guys familiar with the technical representation of this operator.

Modulus in Java: Syntax


Where X is the dividend and Y is divisor.

So simple, isn’t it?

Now that you are well acquainted with the syntax, I am going to use it in the Java program.

Example of Modulus in Java

class ModulusOperator{
public static void main(String[] args){
int num1,num2,result;
System.out.println("num1=26; num2=15");
System.out.println("The result after modulus operation is : "+result);


num1=26 num2=15

The result after modulus operation is: 11

Here, you can see how easy it is to implement this concept in the Java program.

You can also use the modulus operator in finding whether a number is even or odd. Let’s see how!

package com.nullbeans.basics; 
public class Main {
public static void main(String[] args) {
int userInput = 32232;
public static boolean isEvenNumber(int userInput){
if(userInput%2 == 0){
System.out.println("Input is an even number");
return true;
}else {
System.out.println("Input is an odd number");
return false;

Hence, you can see that the modulus operator can be used in many cases. This Modulus in Java can also be used to check whether a number is a prime number or not, or applications that calculated the remaining sum of amounts or likewise.

With this, we come to the end of this article on “Modulus in Java”. I hope you guys are clear with the topics shared and I believe it won’t leave you in any ambiguity now. Keep reading, keep exploring!

If you’re just beginning, then watch at this Java Tutorial to Understand the Fundamental Java Concepts.

Also check out Java Course Online by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe. Edureka’s Java J2EE and SOA training and certification course is designed for students and professionals who want to be a Java Developer. The course is designed to give you a head start into Java programming and train you for both core and advanced Java concepts along with various Java frameworks like Hibernate & Spring. Join our Java Training in Jalandhar

Upcoming Batches For Java Certification Training Course
Course NameDate
Java Certification Training Course

Class Starts on 2nd December,2023

2nd December

SAT&SUN (Weekend Batch)
View Details
Java Certification Training Course

Class Starts on 3rd February,2024

3rd February

SAT&SUN (Weekend Batch)
View Details

Join the discussion

Browse Categories
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

What is Modulus in Java and how does it work?