Advertisement
veronikaaa86

05. Care of Puppy

Jun 18th, 2022
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P05CareOfPuppy {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int availableFoodKg = Integer.parseInt(scanner.nextLine());
  10. int allAvailableFoodGr = availableFoodKg * 1000;
  11.  
  12. int allEatenFood = 0;
  13. String input = scanner.nextLine();
  14. while (!input.equals("Adopted")) {
  15. int currentFood = Integer.parseInt(input);
  16.  
  17. allEatenFood += currentFood;
  18.  
  19. input = scanner.nextLine();
  20. }
  21.  
  22. int diff = Math.abs(allEatenFood - allAvailableFoodGr);
  23. if (allEatenFood <= allAvailableFoodGr) {
  24. System.out.printf("Food is enough! Leftovers: %d grams.", diff);
  25. } else {
  26. System.out.printf("Food is not enough. You need %d grams more.", diff);
  27. }
  28. }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement