04. Food for Pets /Java /Programming Basics Online Exam - 28 and 29 March 2020
Здравейте, моля за помощ.
тук е условието на задачата:
https://judge.softuni.bg/Contests/Practice/Index/2275#6
а тук кода : https://pastebin.com/kg7gr34L
Слагам кода и във въпроса. Предварително благодаря.
Тези два реда ми дават стойност 0 като резултат и не мога да разбера защо?
int percentageFoodDog = totalAmountFoodDog / totalAmountEatenFood;
int percentageFoodCat = totalAmountFoodCat / totalAmountEatenFood;
package Exams.E28_29_2020; import java.util.Scanner; public class P04FoodForPets { public static void main(String[] args) { Scanner scan = new Scanner(System.in); //всеки трети ден бисквитки //бисквитките са 10 % от общо изядената храна int days = Integer.parseInt(scan.nextLine()); double totalAmountFood = Double.parseDouble(scan.nextLine()); int totalAmountFoodDog = 0; int totalAmountFoodCat = 0; int totalAmountEatenFood = 0; int thirdDayFoodDog = 0; int thirdDayFoodCat = 0; for (int i = 1; i <= days; i++) { int amountFoodDogPerDay = Integer.parseInt(scan.nextLine()); int amountFoodCatPerDay = Integer.parseInt(scan.nextLine()); totalAmountFoodDog += amountFoodDogPerDay; totalAmountFoodCat += amountFoodCatPerDay; thirdDayFoodDog = amountFoodDogPerDay; thirdDayFoodCat = amountFoodCatPerDay; } int totalAmountthirdDay = thirdDayFoodCat + thirdDayFoodDog; totalAmountEatenFood = totalAmountFoodCat + totalAmountFoodDog; int test1 = totalAmountFoodDog + 1000; int test2 = totalAmountEatenFood + 1000; double test3 = totalAmountFood / test2; int biscuits = Math.round(totalAmountthirdDay * 10 / 100); int percentageFoodDog = totalAmountFoodDog / totalAmountEatenFood; int percentageFoodCat = totalAmountFoodCat / totalAmountEatenFood; System.out.printf("Total eaten biscuits: %dgr.%n", biscuits); System.out.printf("%.2f%% of the food has been eaten.%n", totalAmountEatenFood / totalAmountFood * 100.0); System.out.printf("%.2f%% eaten from the dog.%n", percentageFoodDog * 100.0); System.out.printf("%.2f%% eaten from the cat.%n", percentageFoodCat * 100.0); } }