Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exam20Feb;
- import java.util.Scanner;
- public class PuppyCare {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int food = Integer.parseInt(scanner.nextLine());
- food *= 1000;
- String command = scanner.nextLine();
- int total = 0;
- while (!command.equals("Adopted")) {
- int eatenFood = Integer.parseInt(command);
- total += eatenFood;
- command = scanner.nextLine();
- }
- if (food >= total) {
- System.out.printf("Food is enough! Leftovers: %d grams.", food - total);
- } else {
- System.out.printf("Food is not enough. You need %d grams more.", Math.abs(food - total));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment