Guest User

Untitled

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