SophiYo

Ex.04.Puppy

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