Advertisement
Ligh7_of_H3av3n

Задача 4.CatFood

Oct 21st, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. package ZadachiOtIzpita2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class CatFood {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int numOfCats = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int groupOne = 0;
  12.         int groupTwo = 0;
  13.         int groupThree = 0;
  14.         double totalFood = 0.00;
  15.  
  16.         for (int i = 1; i <= numOfCats; i++) {
  17.             double food = Double.parseDouble(scanner.nextLine());
  18.             totalFood += food;
  19.  
  20.             if (food >= 100 && food < 200) {
  21.                 groupOne++;
  22.             }
  23.             else if (food < 300) {
  24.                 groupTwo++;
  25.             }
  26.             else if (food < 400) {
  27.                 groupThree++;
  28.             }
  29.         }
  30.         double priceFoodPerDay = (totalFood / 1000 * 12.45);
  31.  
  32.         System.out.printf("Group 1: %d cats.\n", groupOne);
  33.         System.out.printf("Group 2: %d cats.\n", groupTwo);
  34.         System.out.printf("Group 3: %d cats.\n", groupThree);
  35.         System.out.printf("Price for food per day: %.2f lv.", priceFoodPerDay );
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement