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 ?
2 Antworten
+ 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()
+ 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.