Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class hranaZaJivotni {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.print("Number of days: ");
- int days = Integer.parseInt(scan.nextLine());
- System.out.print("Total amount of food: ");
- double totalFood = Integer.parseInt(scan.nextLine());
- int[] dog = new int[days];
- int[] cat = new int[days];
- for (int i = 0; i < days; i++) {
- System.out.printf("Amount of food eaten by dog on day %d: ", i+1);
- dog[i] = Integer.parseInt(scan.nextLine());
- System.out.printf("Amount of food eaten by cat on day %d: ", i+1);
- cat[i] = Integer.parseInt(scan.nextLine());
- }
- scan.close();
- System.out.println();
- int biscuits = 0;
- int totalEatenFromDog = 0;
- int totalEatenFromCat = 0;
- for (int j = 1; j <= days; j++) {
- totalEatenFromDog += dog[j-1];
- totalEatenFromCat += cat[j-1];
- if (j % 3 == 0)
- biscuits += (dog[j-1] + cat[j-1])/10;
- }
- double totalEatenFood = totalEatenFromDog + totalEatenFromCat;
- double percentEatenFood = (totalEatenFood/totalFood)*100;
- double percentEatenFromDog = (totalEatenFromDog/totalEatenFood)*100;
- double percentEatenFromCat = (totalEatenFromCat/totalEatenFood)*100;
- System.out.printf("Total eaten biscuits: %d gr.", biscuits);
- System.out.printf("\n%.2f%% of the food has been eaten.", percentEatenFood);
- System.out.printf("\n%.2f%% eaten from dog.", percentEatenFromDog);
- System.out.printf("\n%.2f%% eaten from cat.", percentEatenFromCat);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement