Advertisement
Ivakis

Торта

Oct 14th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int cakeWidth = Integer.parseInt(scanner.nextLine());
  8. int cakeLength = Integer.parseInt(scanner.nextLine());
  9.  
  10. int cake = cakeWidth * cakeLength;
  11.  
  12. while(true){
  13. String input = scanner.nextLine();
  14.  
  15. if(input.equals("STOP")){
  16. break;
  17. }
  18.  
  19. int pieces = Integer.parseInt(input);
  20. cake = cake - pieces;
  21.  
  22. if(cake < 0){
  23. break;
  24. }
  25. }
  26. if(cake < 0){
  27. System.out.printf("No more cake left! You need %d pieces more.", Math.abs(cake));
  28. }else{
  29. System.out.printf("%d pieces are left.", cake);
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement