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