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 x = Integer.parseInt(scanner.nextLine());
- int y = Integer.parseInt(scanner.nextLine());
- int cakePieces = x * y;
- String input = "";
- while (cakePieces > 0 && !(input = scanner.nextLine()).equals("STOP")) {
- cakePieces -= Integer.parseInt(input);
- }
- if (cakePieces >= 0) {
- System.out.printf("%d pieces are left.\n", cakePieces);
- } else {
- System.out.printf("No more cake left! You need %d pieces more.\n", Math.abs(cakePieces));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement