Silviyaa

Untitled

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