+ 1

Halloween Candy Challenge Help

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){ double h = houses; double dollar = 2 / h; double convert = dollar * 100; int percentage = (int)Math.round(convert); System.out.println(percentage); } } } This is my code and I get the first two samples correct but then the next three that i cannot see are wrong and i do not know why. I am new to coding so please explain any answers very easily

11th Dec 2020, 2:39 PM
Ben Szydlowski
5 Antworten
+ 2
Ben Szydlowski , use Math.ceil method to calculate percentage instead of Math.round.
11th Dec 2020, 3:07 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
Why do you write double convert = dollar *100; ?
17th Apr 2021, 7:53 PM
Chris Güler
Chris Güler - avatar
0
TheWh¡teCat 🇧🇬 that worked thank you! So what exactly does math.ceil do?
11th Dec 2020, 3:23 PM
Ben Szydlowski
11th Dec 2020, 3:28 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
@Ben Szydlowski ceil () The Math. ceil () function returns the next integer that is greater than or equal to the given number.
17th Apr 2021, 7:55 PM
Chris Güler
Chris Güler - avatar