Results 1 to 7 of 7
  1. #1
    Phyxed is offline Member
    Join Date
    Feb 2011
    Posts
    6
    Rep Power
    0

    Default Hey its me again

    I know this will probably be such an easy thing but I cant figure out how to change my 9/blop to give me a 2.5. I keep getting an error. Im under the assumption that casting a double on either the 9 or the blop will give me a result with a 2.5 but i keep getting an error with the possible loss of percision. Any help would be appreciated, and here is the code thus far.

    int blip = 5;
    int blop;

    blop = blip%3;
    blip = 9/(double)blop;
    System.out.println("Today " + blop + " cats");
    System.out.println("caught " + blip + " mice.");

    Thanks again guys,

    Phyxed

  2. #2
    kwgivler is offline Member
    Join Date
    Mar 2011
    Posts
    18
    Rep Power
    0

    Default

    Did you try making blip a double instead of an int?

  3. #3
    Phyxed is offline Member
    Join Date
    Feb 2011
    Posts
    6
    Rep Power
    0

    Default

    I did and I got the same error at line 17 where its blop = blip%3. Is there anyway to force a double on the blip = 9/blop ?because what i have posted originally is giving me an error and its because of that double infront of blop.

  4. #4
    kwgivler is offline Member
    Join Date
    Mar 2011
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by Phyxed View Post
    I did and I got the same error at line 17 where its blop = blip%3. Is there anyway to force a double on the blip = 9/blop ?because what i have posted originally is giving me an error and its because of that double infront of blop.
    Well you could make blip and blop both doubles or use a cast like this:

    Java Code:
    blop = (int) blip % 3;
    I think this is what you want:

    Java Code:
    		double blip = 5;
    		int blop;
    
    		blop = (int) blip % 3;
    		blip = (double) 9 / blop;
    		System.out.println("Today " + blop + " cats");
    		System.out.println("caught " + blip + " mice.");
    Last edited by kwgivler; 03-10-2011 at 11:52 PM.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    When you run into problems like this the best thing to do is experiment. If you think it's going to require a cast, try it. Try casting different to different types until you get it right. When you get it working correctly, take a minute and think about why it works that way and not the other ways.

  6. #6
    Phyxed is offline Member
    Join Date
    Feb 2011
    Posts
    6
    Rep Power
    0

    Default

    I appreciate the help a lot guys thank you very much!

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Please mark your thread solved with the thread tools if you are done.

Posting Permissions

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