0

Fruit Bowl

Hello ! I don’t get where I made a mistake. Test 3-5 fail and I can’t see why? import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int fruit = input.nextInt(); while(fruit%2!=0||fruit<0||fruit>Integer.MAX_VALUE){ fruit=input.nextInt(); } int apples=fruit/2; if(fruit==0||fruit<6) System.out.println(0); else{ if(apples<3) System.out.println(0); else System.out.println(apples/3); } } }

23rd Jan 2020, 12:37 PM
Georgi
2 odpowiedzi
- 1
Georgi , I think you don't need loop, you don't even need so many conditions to check => you can solve it in 3-4 lines. Just perform the arithmetic operations => first read the fruits, then calculate the apples, then the pies and print the pies 🐱 Also avoid to put many conditions in an loop or if-else checks, because it could be difficult to follow the logical chain and find the mistake.
23rd Jan 2020, 12:56 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
- 2
easier than you think. mersi ;)
23rd Jan 2020, 1:48 PM
Georgi