SHARE
TWEET

Untitled

a guest Oct 18th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Beginning;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Demo {
  6.     public static void main(String[]args){
  7.         Scanner scanner = new Scanner(System.in);
  8.         int length=Integer.parseInt(scanner.nextLine());
  9.         int width=Integer.parseInt(scanner.nextLine());
  10.         int area=length*width;
  11.         int totalPieces=0;
  12.  
  13.         String input=scanner.nextLine();
  14.         while (!input.equalsIgnoreCase("stop")){
  15.             int pieces=Integer.parseInt(input);
  16.             totalPieces+=pieces;
  17.             if(area-totalPieces<0){
  18.                 System.out.printf("No more cake left! You need %d pieces more.",Math.abs(totalPieces-area));
  19.                 break;
  20.             }
  21.             input=scanner.nextLine();
  22.         }
  23.         if(input.equalsIgnoreCase("stop")) {
  24.  
  25.             System.out.printf("%d pieces are left.", area - totalPieces);
  26.         }
  27.     }
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top