Modulo


#1



https://www.codecademy.com/courses/learn-java/lessons/introduction-to-java/exercises/math-2?action=lesson_resume

I don't get the idea of modulo. I just can't understand what should I do or what is the mathematical calculation behind it. THX


Replace this line with your code.


#2

When you divide a number.

say if X is divided by Y,

You get two things.

X / Y -- > Quotient say Q

and

X % Y --> Remainder say R

modulo is used to find this R,It means It gives you remainder not quotient.

Example..

13 / 5 -- > gives you Quotient 2.
but
13 % 5 --> gives you Remainder 3.

for more..

http://www.dreamincode.net/forums/topic/273783-the-use-of-the-modulo-operator/


#3

Thanks for this useful information and clear my all doubt the modulo.


#4

the examples provided makes sense to me however in my exercise in Modulo it asked to get to 2. the used this as my example 16 % 7. Wouldn't that come to 2? 7 can go into 16 two times and there would be 2 left over, right?


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.