Results 1 to 3 of 3
  1. #1
    zazarath is offline Member
    Join Date
    Mar 2014
    Posts
    2
    Rep Power
    0

    Default using % with doubles plz explain

    i got my self a learning java for dummies book manged to keep up till i hit this and its corsning me a head ache

    Java Code:
    public class Test
    {
    	
    	public static void main(String[] args)
    	{
    		
    		double x = 5.5, y = 2.0;
    		
    		double q = x / y;
    		double w = x % y;
    		System.out.println(q +"     " + w);
    		
    	}
    }
    outputs 2.75 and 1.5
    Plz explain where the hell 1.5 coming from i going to end up kicking myself for this i know but someone plz put some light on this
    Last edited by zazarath; 03-10-2014 at 12:18 AM.

  2. #2
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    165
    Rep Power
    2

    Default Re: using % with doubles plz explain

    The % is called modulus. It basically stands for remainder. So, when you do 5.5 % 2.0 it finds the remainder. 5.5 / 2 = 2 R 1.5, which has a remainder of 1.5. I hope this helps.

  3. #3
    zazarath is offline Member
    Join Date
    Mar 2014
    Posts
    2
    Rep Power
    0

    Default Re: using % with doubles plz explain

    Quote Originally Posted by pj6444 View Post
    The % is called modulus. It basically stands for remainder. So, when you do 5.5 % 2.0 it finds the remainder. 5.5 / 2 = 2 R 1.5, which has a remainder of 1.5. I hope this helps.
    soo basically your says it dose 5.5 - 2 = 3.5, 3.5 - 2 = 1.5 , cant take 2 from 1.5 so stops

    yup kicking myself

    also tyvm for clearing that up for me (stay tuned for more blonde moments as i am only on page 121 /833)
    Last edited by zazarath; 03-10-2014 at 10:28 AM.

Similar Threads

  1. Error getting doubles???
    By zubbylou in forum New To Java
    Replies: 2
    Last Post: 02-13-2014, 03:49 AM
  2. Replies: 2
    Last Post: 12-13-2010, 01:34 PM
  3. Replies: 3
    Last Post: 12-13-2010, 07:22 AM
  4. Arithmetic using doubles
    By Black_Eye in forum New To Java
    Replies: 4
    Last Post: 10-19-2010, 08:35 AM
  5. Cant use doubles
    By Freakzoyd in forum New To Java
    Replies: 27
    Last Post: 07-24-2010, 04:48 AM

Posting Permissions

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