Advertisement
desislava_topuzakova

Cake

Feb 6th, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 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 width = Integer.parseInt(scanner.nextLine());
  7.         int length = Integer.parseInt(scanner.nextLine());
  8.         int cakeSize = width * length;
  9.  
  10.         for (int i = cakeSize; i > -1; i = cakeSize) {
  11.             String pieces = scanner.nextLine();
  12.             if (pieces.equals("STOP")) {
  13.                 System.out.printf("%d pieces are left.", cakeSize);
  14.                 return;
  15.             }
  16.             Integer pieces2 = Integer.valueOf(pieces);
  17.             cakeSize = cakeSize - pieces2;
  18.         }
  19.         System.out.printf("No more cake left! You need %d pieces more.", Math.abs(cakeSize));
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement