Results 1 to 3 of 3
  1. #1
    Blaedel is offline Member
    Join Date
    Oct 2009
    Location
    Denmark
    Posts
    10
    Rep Power
    0

    Default The modulo operator

    So I'm trying to understand the modulo operator and the use of it in a clock example.

    The line:

    Java Code:
    public void increment()
    {
            value = (value + 1) % limit
    }
    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 = 0

    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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Blaedel is offline Member
    Join Date
    Oct 2009
    Location
    Denmark
    Posts
    10
    Rep Power
    0

    Default Re: The modulo operator

    Oh my god.... yes of course. I simply misread the code.

    Thank you for pointing that out.

    Cheers

Similar Threads

  1. Java OR operator || help!
    By BeardedCamel in forum New To Java
    Replies: 2
    Last Post: 09-19-2011, 09:55 PM
  2. Modulo Headache
    By House in forum New To Java
    Replies: 17
    Last Post: 09-01-2010, 04:29 AM
  3. question about the operator ++
    By dardar in forum New To Java
    Replies: 10
    Last Post: 08-16-2010, 03:39 PM
  4. help with not equal to operator !=
    By manowar689 in forum New To Java
    Replies: 9
    Last Post: 06-15-2010, 01:10 AM
  5. Increment Operator Example
    By abimaran in forum New To Java
    Replies: 10
    Last Post: 11-03-2009, 05:45 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •