Halloween candy round/ceil | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Halloween candy round/ceil

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int houses = input.nextInt(); int bill=2; double proba; //your code goes here do { if (houses<3) System.out.println ("error"); } while (houses<3); { proba=(double) bill / (double) houses; proba*=100; proba=Math.ceil(proba); System.out.println ((int)proba); } } } Hello everyone I have a question about this problem. With this code I passed the test but I don't understand why I have to use Math.ceil and not Math.round (it fail with the 3 last inputs). Thanks

24th Feb 2020, 10:20 AM
Turbobeubeu
Turbobeubeu - avatar
1 Answer
+ 2
Ok so the probleme was my level of english ^^. I thought rounded up to the nearest meant nearest up or down. Problem solved I need to be more careful when I'm reading something not in my mother tongue. Thank you !
24th Feb 2020, 10:31 AM
Turbobeubeu
Turbobeubeu - avatar