Results 1 to 3 of 3
Thread: The modulo operator
- 10-09-2011, 04:22 AM #1
Member
- Join Date
- Oct 2009
- Location
- Denmark
- Posts
- 10
- Rep Power
- 0
The modulo operator
So I'm trying to understand the modulo operator and the use of it in a clock example.
The line:
Where value is defined a an integer is, if, I understand it correctly, meant to increment the "value" value with 1, untill reaching a preset limit at which the value will be set to 0, due to the fact that at this point there will be nothing remaing. i.e 24 % 24 = 0Java Code:public void increment() { value = (value + 1) % limit }
However I thought when the result of the fraction were below zero as in for example 13 % 24 the remaing should be 13... which to me would screw the logic up in the given piece of code.
Well it doesn't and I therefore I must have misunderstood something.
Can anyone help me out there?
Thanks a lot
Martin
-
Re: The modulo operator
What's the remainder of 13 / 24? ... it's 13. So the logic holds.
- 10-09-2011, 04:29 AM #3
Member
- Join Date
- Oct 2009
- Location
- Denmark
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
Java OR operator || help!
By BeardedCamel in forum New To JavaReplies: 2Last Post: 09-19-2011, 08:55 PM -
Modulo Headache
By House in forum New To JavaReplies: 17Last Post: 09-01-2010, 03:29 AM -
question about the operator ++
By dardar in forum New To JavaReplies: 10Last Post: 08-16-2010, 02:39 PM -
help with not equal to operator !=
By manowar689 in forum New To JavaReplies: 9Last Post: 06-15-2010, 12:10 AM -
Increment Operator Example
By abimaran in forum New To JavaReplies: 10Last Post: 11-03-2009, 04:45 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks