Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Cake {
- public static final String STOP = "STOP";
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int widht = Integer.parseInt(scanner.nextLine());
- int heidht = Integer.parseInt(scanner.nextLine());
- int cakeSize = widht * heidht;
- int piecesGiven;
- String input;
- for (int i = 0; i < cakeSize; i++) {
- input = scanner.nextLine();
- if (STOP.equals(input)) {
- System.out.printf("%d pieces are left.", cakeSize);
- break;
- } else {
- piecesGiven = Integer.parseInt(input);
- cakeSize = cakeSize - piecesGiven;
- if (cakeSize < 0) {
- System.out.printf("No more cake left! You need %d pieces more.", - cakeSize);
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment