BapBapuHa

Cake

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