Results 1 to 7 of 7
Thread: Hey its me again
- 03-10-2011, 11:28 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 6
- Rep Power
- 0
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
- 03-10-2011, 11:34 PM #2
Member
- Join Date
- Mar 2011
- Posts
- 18
- Rep Power
- 0
Did you try making blip a double instead of an int?
- 03-10-2011, 11:41 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 6
- Rep Power
- 0
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.
- 03-10-2011, 11:50 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 18
- Rep Power
- 0
Well you could make blip and blop both doubles or use a cast like this:
I think this is what you want:Java Code:blop = (int) blip % 3;
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.
- 03-11-2011, 12:37 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
- 03-13-2011, 07:34 PM #6
Member
- Join Date
- Feb 2011
- Posts
- 6
- Rep Power
- 0
I appreciate the help a lot guys thank you very much!
- 03-13-2011, 09:22 PM #7
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks