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