deyanivanov966

EXAM 31.10 // 02. Deer of Santa

Oct 31st, 2020 (edited)
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int daysWithoutSanta = Integer.parseInt(scanner.nextLine());
  10.         int foodLeftKg = Integer.parseInt(scanner.nextLine());
  11.         double food1DeerKg = Double.parseDouble(scanner.nextLine());
  12.         double food2DeerKg = Double.parseDouble(scanner.nextLine());
  13.         double food3DeerKg = Double.parseDouble(scanner.nextLine());
  14.         double totalFood = (food1DeerKg + food2DeerKg + food3DeerKg) * daysWithoutSanta;
  15.         double foodLeft = Math.floor(foodLeftKg - totalFood);
  16.     double foodNeeded = Math.ceil(totalFood - foodLeftKg);
  17.  
  18.  
  19.         if (totalFood < foodLeftKg) {
  20.             System.out.printf("%s kilos of food left.", (int) foodLeft);
  21.         } else if (totalFood > foodLeftKg) {
  22.             System.out.printf("%s more kilos of food are needed.", (int) foodNeeded);
  23.         }
  24.  
  25.  
  26.  
  27.     }
  28. }
Add Comment
Please, Sign In to add comment