Advertisement
yoilieva6

04. Puppy Care

Dec 11th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class main {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         int foodKg = Integer.parseInt(scan.nextLine());
  7.         String foodIn = scan.nextLine();
  8.  
  9.         int foodG = foodKg * 1000;
  10.         int sumFood = 0;
  11.  
  12.         while (!foodIn.equals("Adopted")) {
  13.             int foodAll = Integer.parseInt(foodIn);
  14.  
  15.             sumFood += foodAll;
  16.             if (foodG < sumFood){
  17.                 System.out.printf("Food is not enough. You need %.0f grams more.", (sumFood * 1.0) - foodG);
  18.                 break;
  19.             }
  20.             foodIn = scan.nextLine();
  21.         }
  22.  
  23.         if (foodG >= sumFood) {
  24.             System.out.printf("Food is enough! Leftovers: %.0f grams.", foodG - (sumFood * 1.0));
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement