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 width = Integer.parseInt(scanner.nextLine());
- int length = Integer.parseInt(scanner.nextLine());
- int cakeSize = width * length;
- for (int i = cakeSize; i > -1; i = cakeSize) {
- String pieces = scanner.nextLine();
- if (pieces.equals("STOP")) {
- System.out.printf("%d pieces are left.", cakeSize);
- return;
- }
- Integer pieces2 = Integer.valueOf(pieces);
- cakeSize = cakeSize - pieces2;
- }
- System.out.printf("No more cake left! You need %d pieces more.", Math.abs(cakeSize));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement