+ 1
Halloween Candy - prints double always
Hello everyone! I'm doing the Halloween Candy Challange right know. Wrote the code, works perfectly, but there is something that won't let me pass it. It doesn't want to output the right format, wich is an integer. Here's the code: https://code.sololearn.com/c1Qe8h6Z2M67 I tried to convert double to integer with TypeCasting and Double.intValue(). Tried to print (int)percentage too. Used Sololearn's environment and IntelliJ with the same results. It always outputs like 67.0 or 50.0. I wonder if I miss anything here. Thank you all for any kind of hints! Love, Llama
4 odpowiedzi
+ 2
System.out.println((int)Math.ceil(percentage));
+ 1
Thank you Jayakrishnain! It looks so simple and annoying. :D
0
It's so simple but why annoying..?
Task is asked to round-up result value and print integer equalent..
Anyways ,
you're welcome...
0
If you don't want to use Typecasting :
System.out.println(Math.round(Math.ceil(percentage)));
System.out.println(Double.valueOf(Math.ceil(percentage)).intValue());