Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package S5_WhileLoops;
- 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 cakePieces = width * length;
- boolean arePiecesLeft = true;
- String command = scanner.nextLine();
- while(!command.equals("STOP")) {
- int pieces = Integer.parseInt(command);
- cakePieces = cakePieces - pieces;
- if(cakePieces <= 0) {
- arePiecesLeft = false;
- break;
- }
- command = scanner.nextLine();
- }
- if(!arePiecesLeft) {
- System.out.printf("No more cake left! You need %d pieces more.", Math.abs(cakePieces));
- } else {
- System.out.printf("%d pieces are left.", cakePieces);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement