View Question
 Question
 Subject: modulus division in Java Category: Computers > Programming Asked by: robalan-ga List Price: \$20.00 Posted: 25 Sep 2005 12:45 PDT Expires: 25 Oct 2005 12:45 PDT Question ID: 572449
 ```I'm learning Java programming as a hobby. The modulo operator is confusing me. I have been researching modulus division and can understand 60 mod 60 giving a result of 0. But why does 15 mod 60 = 15 ? I would expect 15 divided by 60 to equal 0.25. Please help, I've been searching the internet for the past few days without any luck.```
 Subject: Re: modulus division in Java Answered By: secret901-ga on 25 Sep 2005 13:19 PDT Rated:
 ```Hi robalan-ga, In Java and other programming languages, the modulo operator, usually represented by the symbol "%" or "mod", finds the remainder of division by one number by another. For example, 60 % 60 = 0 because when you divide 60 into 60, the remainder is 0. By the same reasoning, 15 % 60 = 15 because 15/16 = 0 with a remainder of 15. Thus, the result of a modulo operation between two integers, for example a % b is always an integer between 0 and b-1. I hope this clears up the confusion. If you still need help understanding this concept, please let me know via a request for clarification. secret901-ga Search strategy: http://en.wikipedia.org/wiki/Modulo_operation Java glossary: modulus http://mindprod.com/jgloss/modulus.html``` Clarification of Answer by secret901-ga on 25 Sep 2005 13:20 PDT ```Oops, in the above answer, "15/16" should be changed to "15/60" Thank you, secret901-ga``` Request for Answer Clarification by robalan-ga on 26 Sep 2005 01:26 PDT ```hi secret901-ga, I think I understand it. So the 15 % 60 = 15 because 15 goes into sixty 0.25 times. 0.25 is not an integer. So 15 goes into sixty zero times leaving 15. Is this correct?``` Clarification of Answer by secret901-ga on 26 Sep 2005 07:11 PDT ```Hi robalan-ga, Your reasoning is correct. The modulo operator finds the remainder of a division, not the quotient. Think back to the days in elementary school before you haven't learned decimals yet. When you first learned division, when you divide two numbers you get an integer quotient and a remainder. If you still need help understanding this concept, please let me know before rating this answer. secret901-ga```

 There are no comments at this time.