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