Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FoodForPets_04 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int days = Integer.parseInt(scanner.nextLine());
- double availableFood = Double.parseDouble(scanner.nextLine());
- double totalDog = 0;
- double totalCat = 0;
- double total = 0;
- double totalBiscuits = 0;
- for (int day = 1; day <= days ; day++) {
- int dog = Integer.parseInt(scanner.nextLine());
- int cat = Integer.parseInt(scanner.nextLine());
- totalDog += dog;
- totalCat += cat;
- total += dog + cat;
- if(day % 3 == 0) {
- totalBiscuits += 0.10 * (dog + cat);
- }
- }
- System.out.printf("Total eaten biscuits: %dgr.%n", Math.round(totalBiscuits));
- double percentEaten = total / availableFood * 100;
- System.out.printf("%.2f%% of the food has been eaten.%n", percentEaten);
- double percentByDog = totalDog / total * 100;
- System.out.printf("%.2f%% eaten from the dog.%n", percentByDog);
- double percentByCat= totalCat / total * 100;
- System.out.printf("%.2f%% eaten from the cat.", percentByCat);
- }
- }
Add Comment
Please, Sign In to add comment