Advertisement
aneliabogeva

Cake

Nov 20th, 2020
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Cake {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         Integer width = Integer.parseInt(scanner.nextLine());
  7.         Integer high = Integer.parseInt(scanner.nextLine());
  8.         String piecesTaken = scanner.nextLine();
  9.         Integer cakePieces = width * high;
  10.         Integer counter = 0;
  11.  
  12.         while(!"STOP".equals(piecesTaken)){
  13.             Integer pieces = Integer.valueOf(piecesTaken);
  14.             counter += pieces;
  15.             cakePieces -= pieces;
  16.             if(cakePieces <= 0){
  17.                 break;
  18.             }
  19.             piecesTaken = scanner.nextLine();
  20.         }
  21.         Integer finalPieces = Math.abs(counter - (high*width));
  22.         if((high*width) >= counter){
  23.             System.out.printf("%d pieces are left.", finalPieces);
  24.         }else {
  25.             System.out.printf("No more cake left! You need %d pieces more.",finalPieces);
  26.         }
  27.  
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement