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