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