desislava_topuzakova

05. Puppy Care

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