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