+ 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

31st Aug 2022, 2:29 PM
Zoltán Szabó
4 Respuestas
+ 2
System.out.println((int)Math.ceil(percentage));
31st Aug 2022, 2:37 PM
Jayakrishna 🇮🇳
+ 1
Thank you Jayakrishnain! It looks so simple and annoying. :D
31st Aug 2022, 2:44 PM
Zoltán Szabó
0
It's so simple but why annoying..? Task is asked to round-up result value and print integer equalent.. Anyways , you're welcome...
31st Aug 2022, 3:04 PM
Jayakrishna 🇮🇳
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());
4th Sep 2022, 9:44 PM
Roland
Roland - avatar