Advertisement
Spocoman

Care of Puppy

Sep 2nd, 2024
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 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 foodInKilograms = Integer.parseInt(scanner.nextLine()),
  7.                 availableFoodInGrams = foodInKilograms * 1000;
  8.  
  9.         String command;
  10.         while (!(command = scanner.nextLine()).equals("Adopted")) {
  11.             availableFoodInGrams -= Integer.parseInt(command);
  12.         }
  13.  
  14.         if (availableFoodInGrams >= 0) {
  15.             System.out.printf("Food is enough! Leftovers: %d grams.", availableFoodInGrams);
  16.         } else {
  17.             System.out.printf("Food is not enough. You need %d grams more.", Math.abs(availableFoodInGrams));
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement