Halloween Candy task - java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Halloween Candy task - java

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int houses = input.nextInt(); //your code goes here if(houses>=3){ float res = 200/((float)houses); if(res-Math.floor(res) >= 0.5){ System.out.println((int)Math.ceil(res)); }else{ System.out.println((int)Math.floor(res)); } ; } } } Hi! I don't get why this code doesn't work ( only test 1 and 2 are completed and others are hidden) , can i have some help please ?

16th Feb 2022, 5:39 PM
ViViCouBar
2 Answers
+ 4
A percentage value rounded up to the nearest whole number. use Math.ceil() instead of Math.floor() round up is done with ceil() not floor()
16th Feb 2022, 6:14 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
Thank you ! I misunderstood, i thought i had to round up to the nearest whole number, as the previous one if it was nearer than the next one.
16th Feb 2022, 7:45 PM
ViViCouBar