You code is actually doing

remainder = 3 % 7; // equals 3.

The best way to determine why your code is not doing what you think is to step through your code using a debugger.

All the multiples of 3 & 7 will be multiples of 21, i.e. 21, 42, 63, 84.

Answer from Peter Lawrey on Stack Overflow
🌐
Medium
medium.com › @AlexanderObregon › what-is-javas-modulo-and-how-to-use-it-10e8e464d974
What Is Java’s Modulo (%) and How to Use It | Medium
April 1, 2025 - That small detail makes a big difference in how it behaves, especially when you start working with negative numbers or floating-point values. To get a clear picture of what’s really happening, we need to break it down using both math and Java’s specific rules. ... you might read it as “10 modulo 3.” In Java, this actually means: divide 10 by 3 using integer division, then return what’s left over.
Discussions

modulo - What's the syntax for mod in Java? - Stack Overflow
The modulus operator in Java is the percent character (%). Therefore taking an int % int returns another int. The double equals (==) operator is used to compare values, such as a pair of ints and returns a boolean. This is then assigned to the boolean variable 'isEven'. Based on operator precedence the modulus will be evaluated before the comparison. ... It's a remainder operator, not a modulus operator. 2016-03-30T01... More on stackoverflow.com
🌐 stackoverflow.com
How does the modulus operator work?
This is, in Java code, what the computer actually does: while(a >= b) { a -= b; } return a; //Remainder It simply subtracts b from a until it can't subtract b from a without a going into negative. It then returns the remainder. It's useful to see for example if a number is even. x % 2 will return a remainder of 1 for all odd numbers and 0 for all even numbers. This is why you often see code like boolean even = x % 2 == 0; in code. More on reddit.com
🌐 r/javahelp
6
5
September 19, 2015
modular arithmetic - Not understanding modulo - Mathematics Stack Exchange
Well, for Java programming we have to use the modulo operator, but I just don't get the modulo it self. I hope any of you would be able to explain in simple words and with an example what it does. ... J. M. ain't a mathematician · 77.1k88 gold badges223223 silver badges348348 bronze badges ... $\begingroup$ It means the remainder on division. For example $18 \equiv 3 ... More on math.stackexchange.com
🌐 math.stackexchange.com
November 23, 2012
What the HELL is a modulo?
The modulo operator returns the "remainder" of a division. If you think back to your early days at school, when you first learned dividing using long divisions , you learned that for 14/4 the result is 3 and the remainder is 2. Because "4" fits "3" times in '14", but then you still have a remainder of "2" so that: 14 = 4 x 3 + 2 Now, why do they suggest using the modulo operator to get the different numbers (6, 4, 1). Well, let's start from the right. If we divide 641/10, we know that it fits 64 times inside 641 and the remainder is 1. In java terms this is: int lastDigit = 641 % 10; // 1 Now, you can repeat the same process over and over again, however, we need to "shift" the number a bit. For example, if we want to know the second digit, we first divide 641 by 10, so that we only have 64. Now we can just retrieve the last digit again by using the modulo operator: int secondDigit = 641 / 10 % 10; // = 64 % 10 = 4 Now, you should start to see a system here. You can keep doing this trick over and over again, but in stead of dividing by 10, you divide by 100, 1000, 10000, 100000, ... and you get the next digit every time. In your case, the left digit can be retrieved by using: int firstDigit = 641 / 100 % 10; // = 6 % 10 = 6 In this case, it's pretty "useless" to use the modulo operator, because if you have a number with only 3 digits, dividing by 100 will already yield the left most digit. However, let's say that our number was 1234, then we would get: int digit = 1234 / 100 % 10; // = 12 % 10 = 2 More on reddit.com
🌐 r/learnjava
31
0
October 30, 2016
🌐
GeeksforGeeks
geeksforgeeks.org › java › modulo-or-remainder-operator-in-java
Modulo or Remainder Operator in Java - GeeksforGeeks
January 24, 2026 - The modulo operator (%) in Java is an arithmetic operator used to find the remainder after division of one number by another. It is commonly used in mathematical calculations, loops, condition checking, and number-based logic.
🌐
Baeldung
baeldung.com › home › java › core java › the modulo operator in java
The Modulo Operator in Java | Baeldung
September 3, 2025 - The remainder is what remains after dividing 11 (the dividend) by 4 (the divisor), which in this case is 3. For the same reason a division by zero isn’t possible, it’s not possible to use the modulo operator when the right-side argument is zero.
🌐
Codedamn
codedamn.com › news › java
What is Modulo/Modulus/Remainder Operator In Java?
November 20, 2023 - In Java, the modulo operator is used with the following syntax: operand1 % operand2. Here, operand1 is the dividend and operand2 is the divisor. The result of this operation is the remainder when operand1 is divided by operand2.
🌐
Mkyong
mkyong.com › home › java › java mod examples
Java mod examples - Mkyong.com
March 9, 2020 - In Java, we can use Math.floorMod() to describe a modulo (or modulus) operation and % operator for the remainder operation. See the result: | rem & +divisor| rem & -divisor | mod & +divisor | mod & -divisor | | :-------------| :------------- | :------------- | :--------------| | -5 rem 3 = -2 | -5 rem -3 = -2 | -5 mod 3 = 1 | -5 mod -3 = -2 | | -4 rem 3 = -1 | -4 rem -3 = -1 | -4 mod 3 = 2 | -4 mod -3 = -1 | | -3 rem 3 = 0 | -3 rem -3 = 0 | -3 mod 3 = 0 | -3 mod -3 = 0 | | -2 rem 3 = -2 | -2 rem -3 = -2 | -2 mod 3 = 1 | -2 mod -3 = -2 | | -1 rem 3 = -1 | -1 rem -3 = -1 | -1 mod 3 = 2 | -1 mod
🌐
Reddit
reddit.com › r/javahelp › how does the modulus operator work?
r/javahelp on Reddit: How does the modulus operator work?
September 19, 2015 -

I apologise in advance if this is a stupid question, but I've looked everywhere and every explanation I've found has been way above my pay grade.

I've been studying java for a grand total of one week. My lecturer gave us notes that cover the modulus, but after reading them I'm still none the wiser. The examples he gives don't seem consistent and I'm just getting more and more confused.

The exercise involves trying convert 174 pounds into stone and pounds using the modulus, but I honestly have no idea where the modulus goes or how it works, or what numbers I'm supposed to put where. I'd be grateful for literally any explanation at this point.

Find elsewhere
Top answer
1 of 3
3

If you mean Modulo operation like "3 mod 2" then this is just the remainder when you divide 3 by 2. 3 divided by 2 is 1 with a remainder of 1, so "3 mod 2" is 1.

In order to understand this, you must first be able to do long division by hand (using calculators doesn't work since you get decimal numbers). If you know long division, then it's really easy to calculate any number modulo any other number (natural numbers only).

For example 4 mod 2 is 0 because 4 is divisible by 2.

16 mod 3 is 1 because 16 divided by 3 is 5 with a remainder of 1. In other words 3 goes into 16 5 times and there is a remainder of 1.

It's all about remainders! Once you get comfortable with the definition you can learn some algebraic rules of manipulating these remainders.

2 of 3
0

When you first learned about division, it might even have been before you learned about fractions. If you are dividing integers ("whole numbers") then instead of writing $14 \div 3 = 4\frac{2}{3}$ you can write $$14 \div 3 = 4 \text { remainder } 2.$$

The modulo operator is just the function that takes two integers and gives the remainder when the first is divided by the second: $$14 \mod 3 = 2, \quad$$

The other operator of integer division is usually called $\text{div}$, and $x \text{ div } y$ is defined, as you'd expect, to be the greatest $n$ such that $y \times n \leq x$. So for example $14 \text{ div }3 = 4$. And we can define $\text{mod}$ formally as: $$x \mod y := x- (y \times (x \text{ div } y)).$$

Is this clear?

🌐
Java67
java67.com › 2014 › 11 › modulo-or-remainder-operator-in-java.html
How to use Modulo , Modulus, or Remainder Operator in Java? [Example] | Java67
I think you are right that they are actually remainder operator which is also loosely called modulus operator but it doesn't really mean modulus operator of Maths which you explained here. Its also interesting to know that Lisp and Ada has both. ThxDelete ... Load more... Feel free to comment, ask questions if you have any doubt. ... How to Check if a Given Point Lies Inside a Triang... What is Constructor in Java and How it works? [wit... Difference between ReentrantLock vs synchronized l... Difference between an ordered and a sorted collect... 3 Examples to Loop Map in Java - Foreach vs Iterator
🌐
Xperti
xperti.io › home › how to use modulo, modulus, or remainder operator in java?
How To Use Mod Operator In Java
August 17, 2022 - It is a lesser-known fact because real number division usually does not result in a remainder and this feature also does not exist in various other programming languages such as C or C++ where the mod operator only works with int operands. The evaluated result of using the mod operator with real values will also be a real value. For example, 6.32 % 2 will evaluates to 0.32 since the division is 3 with a remainder of 0.32.
🌐
IONOS
ionos.com › digital guide › websites › web development › java modulo
How to use the Java modulo operator - IONOS
December 18, 2024 - For example, if you divide 11 by 4, you’ll have a remainder of 3 (2 x 4 = 8, 11 - 8 = 3). This can lead to problems in pro­gram­ming. Web Hosting Hosting that scales with your ambitions · Stay online with 99.99% uptime and robust security ... That’s what the Java modulo operator is for.
🌐
Wikipedia
en.wikipedia.org › wiki › Modulo
Modulo - Wikipedia
1 month ago - For example, the expression "5 mod 2" evaluates to 1, because 5 divided by 2 has a quotient of 2 and a remainder of 1, while "9 mod 3" would evaluate to 0, because 9 divided by 3 has a quotient of 3 and a remainder of 0. Although typically performed with a and n both being integers, many computing ...
🌐
Quora
quora.com › Can-you-explain-the-differences-between-mod-and-in-Java
Can you explain the differences between mod and % in Java? - Quora
Java (programming languag... ... It is basically the same thing. By mod, i presume you are referring to the mod in python. Mod is going to return the remainder. In the same way the % sign which we call modulus in java returns the remainder.
🌐
Javatpoint
javatpoint.com › java-mod-example
Java Mod Example - Javatpoint
Java Mod Example with java tutorial, features, history, variables, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
AlgoCademy
algocademy.com › link
Modulo Operator in Java | AlgoCademy
Jump Game in Java · TL ; DR: The modulo operator (%) calculates the remainder of dividing two values: System.out.println(10 % 2); // Output: 0 System.out.println(15 % 4); // Output: 3 System.out.println(20 % 3); // Output: 2 · It can also ...
🌐
Modulo
ctp.mkprog.com › en › java › modulo
Java | Modulo: % | Easy language reference
Java · Using the modulo operator we can calculate the remainder after integer division. by using the modulo operator we can easily test the divisibility of integers, if the result is 0, then the number is divisible without a remainder. par1 % par2Used keywords: % par1 - Any number · par2 ...
🌐
Runestone Academy
runestone.academy › ns › books › published › apcsareview › VariableBasics › operators.html
3.5. Operators — AP CSA Java Review - Obsolete
Modulo gives you the remainder after the division. ... When you divide 158 by 10 you get a remainder of 8. ... 8 goes into 3 no times so the remainder is 3.
🌐
Edureka
edureka.co › blog › mod-method-in-java
Modulus in Java | Remainder or Modulus Operator in Java | Edureka
July 5, 2024 - Modulus in Java is an Operator. % is also known as the modulus or remainder operator. The % operator returns the remainder of two numbers
🌐
Cafeaulait
cafeaulait.org › course › week2 › 15.html
Hello The Remainder or Modulus Operator in Java - Cafe au Lait
September 12, 2002 - class Remainder { public static void main (String args[]) { int i = 10; int j = 3; System.out.println("i is " + i); System.out.println("j is " + j); int k = i % j; System.out.println("i%j is " + k); } } ... Perhaps surprisingly the remainder operator can be used with floating point values as well. It's surprising because you don't normally think of real number division as producing remainders. However there are rare times when it's useful to ask exactly how many times does 1.5 go into 5.5 and what's left over?