Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Pet {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int daysCount=Integer.parseInt(scanner.nextLine());
- double totalFoodQuantity=Double.parseDouble(scanner.nextLine());
- double biscuitsCountTotal=0;
- double totalFoodEaten=0;
- double dogPercent=0;
- double catPercent=0;
- double dogAteTotal = 0;
- double catAteTotal = 0;
- for (int i=1; i<=daysCount;i++){
- double biscuitsCount = 0;
- double dogAte=Double.parseDouble(scanner.nextLine());
- double catAte=Double.parseDouble(scanner.nextLine());
- if (i%3==0){
- biscuitsCount=0.1*(dogAte+catAte);
- biscuitsCountTotal += biscuitsCount;
- }
- totalFoodEaten=totalFoodEaten+dogAte+catAte;
- dogAteTotal += dogAte;
- catAteTotal += catAte;
- }
- double percentFood=(totalFoodEaten/totalFoodQuantity) * 100;
- dogPercent=(dogAteTotal/totalFoodEaten) * 100;
- catPercent=(catAteTotal/totalFoodEaten) * 100;
- System.out.printf("Total eaten biscuits: %dgr.\n", Math.round(biscuitsCountTotal));
- System.out.printf("%.2f%% of the food has been eaten.\n",percentFood);
- System.out.printf("%.2f%% eaten from the dog.\n", dogPercent);
- System.out.printf("%.2f%% eaten from the cat.\n", catPercent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement