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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How does Modulo work?

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How does Modulo work?

    Quote Originally Posted by helloworld922 View Post
    modulo gets the remainder.

    It can be read as what is the remainder of 3/6? The answer is 3.
    Thank you for your reply.

    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. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How does Modulo work?

    Quote Originally Posted by Mr.nuub View Post
    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.

    Quote Originally Posted by Mr.nuub View Post
    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?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Why won't this for loop work?
    By vwillis in forum Loops & Control Statements
    Replies: 1
    Last Post: October 14th, 2011, 12:49 PM
  2. Why does this not work?
    By Spidey1980 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 12th, 2011, 09:47 AM
  3. onchange does not work
    By jai in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: March 9th, 2011, 04:10 AM
  4. How do get and set methods work??
    By merdzins in forum Object Oriented Programming
    Replies: 2
    Last Post: December 25th, 2010, 03:17 AM
  5. please tell me why this code does not work
    By amr in forum Java Theory & Questions
    Replies: 9
    Last Post: December 6th, 2010, 06:46 PM