Advertisement
desislava_topuzakova

06. Shelter for Cats

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