+ 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.
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.
+ 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...đ€Łđ€Łđ€Ł
+ 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! đâïž
+ 2
Using the ceil() method worked but I had to convert my double number type to an integer. Thanks for the help.