Help with halloween candy on code coach? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help with halloween candy on code coach?

I was trying to solve the halloween candy problem on code coach with Java. I got stuck at a point where I was asked to round my result to the nearest integer. Can someone please explain the solution to me?

14th Oct 2020, 10:27 AM
Yisa Zaccheaus
Yisa Zaccheaus - avatar
3 Answers
+ 4
Import the math module at the top of your program like this import java.lang.Math.*; Then use this in the result System.out.println(Math.ceil(result));
14th Oct 2020, 10:41 AM
Ruba Kh
Ruba Kh - avatar
+ 1
You don't need to import it, it's already there just use Math.round
14th Oct 2020, 11:17 AM
Ankit
+ 1
Ankit is right you do not have to import math, but you should use ceil function because in the question specified rounding it up
14th Oct 2020, 11:23 AM
Ruba Kh
Ruba Kh - avatar