galinyotsev123

ProgBasicsExam1and2December2018-E04puppyCare

Dec 30th, 2018
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class E04puppyCare {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int food = Integer.parseInt(scanner.nextLine());
  9. int foodInGrams = food * 1000;
  10. int eatedFood = 0;
  11.  
  12. while (true)
  13. {
  14. String porcion = scanner.nextLine();
  15. if (porcion.equals("Adopted"))
  16. {
  17. break;
  18. }
  19. eatedFood += Integer.parseInt(porcion);
  20. }
  21.  
  22.  
  23. if (eatedFood <= foodInGrams)
  24. {
  25. System.out.printf("Food is enough! Leftovers: %d grams.", foodInGrams-eatedFood);
  26. }
  27. else
  28. {
  29. System.out.printf("Food is not enough. You need %d grams more.",eatedFood - foodInGrams);
  30. }
  31.  
  32.  
  33. }
  34. }
Add Comment
Please, Sign In to add comment