stoyanoff

Care of Puppy

Jul 30th, 2020
1,390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package Izpit;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Test {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int foodKilos = Integer.parseInt(scanner.nextLine());
  10.         String command = scanner.nextLine();
  11.         int foodInGrams = foodKilos * 1000;
  12.         int eatenFoodAmount = 0;
  13.  
  14.  
  15.         while (!command.equals("Adopted")) {
  16.             int eatenFood = Integer.parseInt(command);
  17.             eatenFoodAmount += eatenFood;
  18.             command = scanner.nextLine();
  19.         }
  20.  
  21.  
  22.         if (eatenFoodAmount <= foodInGrams) {
  23.             System.out.printf("Food is enough! Leftovers: %d grams.", foodInGrams - eatenFoodAmount);
  24.         } else {
  25.             System.out.printf("Food is not enough. You need %d grams more.", eatenFoodAmount - foodInGrams);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment