Advertisement
Guest User

Untitled

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