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