Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: How does Modulo work?

1. ## How does Modulo work?

Hello everyone,

Could someone explain to me how the modulo works. I understand that 6%3=0 because 6/3=2.0 with no remainder.
But I don't understand that 3%6=3 because 3/6=0.5

Is this because 0.5 is not an int and so it gets 0? So 0 * 6 = 0 and it leaves 3? I have no idea how to read this.

I hope someone can help me out with this

Thank you

2. ## Re: How does Modulo work?

modulo gets the remainder.

It can be read as what is the remainder of 3/6? The answer is 3.

3. ## Re: How does Modulo work?

Originally Posted by helloworld922
modulo gets the remainder.

It can be read as what is the remainder of 3/6? The answer is 3.

Now what is the remainder of 2/18? The answer is 16 with your way of looking at it right? But the correct answer is 2.

I know it is a silly question, but I really need more theory than that single line you gave me.

4. ## Re: How does Modulo work?

Originally Posted by Mr.nuub
Now what is the remainder of 2/18? The answer is 16 with your way of looking at it right? But the correct answer is 2.
Wrong. With "his way of looking at it", the answer is 2. How many times does 18 go into 2? Zero times, with a remainder of 2. Exactly how 6 goes into 3 zero times with a remainder of 3.

Originally Posted by Mr.nuub
I know it is a silly question, but I really need more theory than that single line you gave me.
Then you should have thrown together a test program that ran some more examples, or did more division by hand. For example, when you say 3/6 is .5, how are you arriving at that answer?