FAQ: Introduction to Java - Math: %


This community-built FAQ covers the “Math: %” exercise from the lesson “Introduction to Java”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Java

FAQs on the exercise Math: %

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


hello, I’m Olguine a beginner at programming.I don’t really understand modulo notion could you please help.


Starting with Java, rather than JavaScript is a bit like jumping into the deep end before learning to tread water. You will find the JavaScript course a little easier going and will give you an opportunity to work in a little more forgiving environment.

What level of maths have you reached? Do you understand long division?


What am I missing here? The explanation says for us to use % and not /, but when I try with %, I get it wrong and when I try with a /, I get it right.

  1. The modulo operator - represented in Java by the % symbol - returns the remainder of dividing two numbers.

For example, 15 % 6 will return the value of 3 , because that is the remainder left over after dividing 15 by 6.

Use the modulo operator to set the variable myRemainder equal to 2 . You can use any two numbers that return a remainder value of 2 .

Correct ( int myRemainder = 4 / 2;)
Wrong ( int myRemainder = 4 % 2;)

What am I missing?



What will be the remainder of 4 divided by 2?

Think in algebraic terms…

x % a = 2

Let’s throw something into the mix, the quotient…

x - q * a = R

In any division, a > R, and if we let q = 1 we have,

x - a = 2

which means we can substitute any number for a so long as it is greater than 2.

x = 2 + 3

5 % 3 = 2

which in program terms, means,

5 % 3 == 2    // true


Can you not use any number with a remainder of 2 such as 10 % 4 or 68 % 33? These have an answer of 2 r 2, or is it only supposed to be 1 r 2. Both above examples threw an error in the code.


The lesson instruction says we can use any two numbers, so I’m not sure what the issue might be. Did you try,

5 % 3