Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

How to get rid of "possible lossy conversion from double to int" error, Self-check 2.9

+3 votes
asked Sep 7 in CSC 211 (F17) by Gage Soat (570 points)

3 Answers

+1 vote
If you look at the desired output, it asks for a number different than what is in the code. That may help you solve your problem with ints and doubles.
answered Sep 7 by Kathryn Clark (1,391 points)
+1 vote
I don't have the exact problem handy, but the issue going on here is that somewhere you're directly converting (or casting, as we computer sciencers say) a double, which can have decimals, to an int, which can't. This isn't necessarily a bad thing, but you lose some information when you do this. For example, the double 0.86 converted to an int becomes 0. Even if you try to convert back, you get 0.0; all the information the double has that the int can't is lost.
answered Sep 7 by Jonathan Meir (880 points)
+1 vote
The way it is set up before the corrections is storing a double into an int variable which can't be done because you're losing data.  You have to come up with a way to tell java to convert that double into an int.
answered Sep 7 by Bryson Adcock (857 points)