aneliabogeva

PuppyCare

Dec 13th, 2020
37
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class PuppyCare {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         Integer food = Integer.parseInt(scanner.nextLine());
  7.         Integer totalFood = food * 1000;
  8.         String command = scanner.nextLine();
  9.         Integer totalGrams = 0;
  10.  
  11.         while (!"Adopted".equals(command)){
  12.             Integer grams = Integer.valueOf(command);
  13.             totalGrams += grams;
  14.             command = scanner.nextLine();
  15.         }
  16.         Integer diff = Math.abs(totalFood - totalGrams);
  17.         if(totalGrams <= totalFood){
  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. }
  24.  
RAW Paste Data