+ 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
5 Réponses
+ 2
Ben Szydlowski , use Math.ceil method to calculate percentage instead of Math.round.
+ 1
Why do you write double convert = dollar *100; ?
0
TheWh¡teCat 🇧🇬 that worked thank you! So what exactly does math.ceil do?
0
Ben Szydlowski , you can find more info about it here : https://www.tutorialspoint.com/java/lang/math_ceil.htm
0
@Ben Szydlowski ceil () The Math. ceil () function returns the next integer that is greater than or equal to the given number.