aneliabogeva

Cake

Nov 20th, 2020
445
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×