Advertisement
Ivakis

Cake

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