Advertisement
Spocoman

06. Cake

Aug 29th, 2024
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Cake {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int x = Integer.parseInt(scanner.nextLine());
  7.         int y = Integer.parseInt(scanner.nextLine());
  8.         int cakePieces = x * y;
  9.  
  10.         String input = "";
  11.         while (cakePieces > 0 && !(input = scanner.nextLine()).equals("STOP")) {
  12.             cakePieces -= Integer.parseInt(input);
  13.         }
  14.  
  15.         if (cakePieces >= 0) {
  16.             System.out.printf("%d pieces are left.\n", cakePieces);
  17.         } else {
  18.             System.out.printf("No more cake left! You need %d pieces more.\n", Math.abs(cakePieces));
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement