Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int lenght = Integer.parseInt(scan.nextLine());
- int width = Integer.parseInt(scan.nextLine());
- int piecesTaken = 0;
- int allPieces = lenght * width;
- String stop = "";
- while (piecesTaken < allPieces) {
- stop = scan.nextLine();
- if (!stop.equals("STOP")) {
- int portion = Integer.parseInt(stop);
- piecesTaken = piecesTaken + portion;
- } else {
- System.out.printf("%d pieces are left.", allPieces - piecesTaken);
- break;
- }
- }
- if (piecesTaken >= allPieces) {
- System.out.printf("No more cake left! You need %d pieces more.", piecesTaken - allPieces);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment