Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int foodKg = Integer.parseInt(scan.nextLine());
- String foodIn = scan.nextLine();
- int foodG = foodKg * 1000;
- int sumFood = 0;
- while (!foodIn.equals("Adopted")) {
- int foodAll = Integer.parseInt(foodIn);
- sumFood += foodAll;
- if (foodG < sumFood){
- System.out.printf("Food is not enough. You need %.0f grams more.", (sumFood * 1.0) - foodG);
- break;
- }
- foodIn = scan.nextLine();
- }
- if (foodG >= sumFood) {
- System.out.printf("Food is enough! Leftovers: %.0f grams.", foodG - (sumFood * 1.0));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement