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