dividend / divisor = quotient with a remainder

Just do your division as if both numbers (dividend and divisor) where positive. When you're done, if both numbers were positive, the quotient is positive. If both numbers were negative, the quotient is positive. If one (and only one) of the two is negative, then the quotient is negative.

So -45 / 7 would be -6 with a remainder of 3. Actually, now that you brought it up, it probably should be a remainder of -3 since [quotient * divisor + remainder = dividend].

-6 * 7 + (-3) = 45.

Or if the remainder is always supposed to be positive, the answer could be -7 with a remainder of 4: -7 * 7 + 4 = 45. Bottom line is I thought I knew the answer but I guess I don't. It's been too long since I studied that I guess.

SINCE:

dividend = quotient (multiplier * divisor) + remainder

such that

dividend > quotient

so remainder = 4

]]>Now I misunderstood.

]]>

]]>

VVV

o_O

LLLJ]]>

http://en.wikipedia.org/wiki/Modulo_operation

http://mathworld.wolfram.com/Mod.html]]>

For example:

But this depends. You should see some java help for the java %.]]>

I'm not interested in how the modulus operation works physically, but how I figure out the answer to the problems mathematically so I know where I can use them in my program or what they are doing when they appear.

]]>When programming in Java, or really any high level language, it's not so much important to understand how things work. That only starts to make sense when you get down to the assembly level.

I don't agree. If you have some very big messy program, for example, and if it uses many modulus in it, and if it doesn't do what it's supposed to do, then you should know what's happening around the %, because the mistake may be there. If you don't know, you might pass the error, without noticyng it and this can cost you a big headache.

]]>Just do your division as if both numbers (dividend and divisor) where positive. When you're done, if both numbers were positive, the quotient is positive. If both numbers were negative, the quotient is positive. If one (and only one) of the two is negative, then the quotient is negative.

So -45 / 7 would be -6 with a remainder of 3. Actually, now that you brought it up, it probably should be a remainder of -3 since [quotient * divisor + remainder = dividend].

-6 * 7 + (-3) = 45.

Or if the remainder is always supposed to be positive, the answer could be -7 with a remainder of 4: -7 * 7 + 4 = 45. Bottom line is I thought I knew the answer but I guess I don't. It's been too long since I studied that I guess.

]]>