Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement