Advertisement
Spocoman

Cat Shelter

Sep 2nd, 2024
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int foodGrams = Integer.parseInt(scanner.nextLine()) * 1000;
  7.  
  8.         String command;
  9.         while (!(command = scanner.nextLine()).equals("Adopted")) {
  10.             foodGrams -= Integer.parseInt(command);
  11.         }
  12.  
  13.         if (foodGrams >= 0) {
  14.             System.out.printf("Food is enough! Leftovers: %d grams.\n", foodGrams);
  15.         } else {
  16.             System.out.printf("Food is not enough. You need %d grams more.\n", Math.abs(foodGrams));
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement