+ 1

I am getting error in line 3 , 4 & 5 in Halloween Candy ....Here is my code

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int houses = input.nextInt(); double chances = ((double )2)/houses*100; double a = Math.round(chances); System.out.print((int)a); } }

20th Dec 2020, 3:14 PM
Baisa
Baisa - avatar
5 ответов
+ 6
You should use ceil() function instead of round() since we have to round up the nearest integer.
20th Dec 2020, 3:33 PM
Simba
Simba - avatar
+ 4
😏 A.D singh.. 😎 No error in Code. Are you talking about test case?
20th Dec 2020, 3:31 PM
A͢J
A͢J - avatar
+ 4
😏 A.D singh.. 😎 First do Math.ceil then Math.round like System.out.print(Math.round(Math.ceil(chances)));
20th Dec 2020, 3:33 PM
A͢J
A͢J - avatar
+ 1
Thank you ....
20th Dec 2020, 3:37 PM
Baisa
Baisa - avatar
0
Yes..
20th Dec 2020, 3:32 PM
Baisa
Baisa - avatar