+ 1

Halloween Candy Challenge

import java.util.Scanner; import java.lang.Math; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int houses = input.nextInt(); input.close(); double proba = (double)2 / houses; double success = proba * 100; System.out.println(Math.round(success)); //your code goes here } } This is my java code to solve the Halloween candy task but I only pass the first two tests and am unable to pass the others I can't view.

3rd Feb 2024, 9:06 PM
Olayemi Oseni
4 Answers
+ 4
Read the rounding requirement more closely: "Output Format A percentage value rounded up to the nearest whole number." Your code is only rounding, not rounding up. There is a ceil() method for that.
4th Feb 2024, 12:07 AM
Brian
Brian - avatar
+ 4
Brian For foreign citizens using a translator, this task is translated as follows: — "Output format The percentage value rounded to the nearest integer.", which is what the round() method does...😎 I have been reporting this for many years, but they only argue with me in vain saying that I am wrong. And students make this mistake year after year and do not understand what they want from them...đŸ€ŁđŸ€ŁđŸ€Ł
4th Feb 2024, 1:43 AM
Solo
Solo - avatar
+ 3
Thank you, Solo. I was unaware that there could be a translation failure. That does explain why so many struggle with this task. It is not always due to overlooking the requirement, but that the requirement is lost in translation! đŸ‘âœŒïž
4th Feb 2024, 5:38 AM
Brian
Brian - avatar
+ 2
Using the ceil() method worked but I had to convert my double number type to an integer. Thanks for the help.
4th Feb 2024, 12:59 PM
Olayemi Oseni