Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package While_Loop.While_Loop_Exercise;
- import java.util.Scanner;
- public class E06Cake {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int cakeW = Integer.parseInt(scanner.nextLine());
- int cakeL = Integer.parseInt(scanner.nextLine());
- if (cakeW <= 0 || cakeL <= 0) {
- System.out.println("ERROR: NO CAKE");
- return;
- }
- String input = scanner.nextLine();
- int piecesAll = cakeW * cakeL;
- int piecesTaken = 0;
- while (!input.equals("STOP")) {
- int pieces = Integer.parseInt(input);
- piecesTaken += pieces;
- if (piecesTaken >= piecesAll) {
- System.out.printf("No more cake left! You need %d pieces more.", piecesTaken - piecesAll);
- return;
- }
- input = scanner.nextLine();
- }
- System.out.printf("%d pieces are left.", piecesAll - piecesTaken );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement