+ 2

Case 3 and 4 Halloween Candy - Java

I solved it but case 3 and 4 isn't solved. I thought that one of the cases is that "houses" can't be lower than 3, but I guess not My code: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int houses = 0; while (houses < 3){ houses = input.nextInt(); } //your code goes here int bill = 2 *100; int billChance = bill / houses; houses = houses % 2; billChance = billChance + houses ; System.out.println(billChance); } }

15th Jan 2020, 2:18 PM
fick
3 odpowiedzi
0
Edited: OK. Why you are changing given code..? By your logic, For ex: if Bill =2 House=3 200/3=66 If house =5 200/5=40 If house =4 200/4=50 Finally Output : 67 41 50 40 has no fraction part but still rounded up to 41.. Am I right? Edit: use a double type for dollar. Use a ciel function to round up result..
15th Jan 2020, 7:27 PM
Jayakrishna 🇮🇳
+ 1
Thanks, and I changed the upper code because it says that the int should be >= to 3 and I thought that that is one of the cases
15th Jan 2020, 9:33 PM
fick
0
This code works guys: 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 int chances = 200/houses; if(200%houses!=0) System .out .println (chances+1); else System .out .println (chances); } }
5th Apr 2021, 5:23 AM
Mario Enrique Zayas Leal
Mario Enrique Zayas Leal - avatar