Advertisement
Lyubohd

Cake

Feb 9th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Demo {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         int length = Integer.parseInt(scan.nextLine()); //A
  8.         int weight = Integer.parseInt(scan.nextLine()); //B
  9.  
  10.         int cakeArea = length * weight; // A * B
  11.  
  12.         String input = scan.nextLine();
  13.  
  14.         while (!"STOP".equals(input)) {
  15.             int number = Integer.parseInt(input);
  16.             cakeArea -= number;
  17.             if (cakeArea < 0) {
  18.                 System.out.printf("No more cake left! You need %d pieces more.", Math.abs(cakeArea));
  19.                 break;
  20.             }
  21.             input = scan.nextLine();
  22.         }
  23.  
  24.         if (cakeArea >= 0) {
  25.             System.out.printf("%d pieces are left.", cakeArea);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement