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