Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Cake_06 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int widthCake = Integer.parseInt(scanner.nextLine());
- int lengthCake = Integer.parseInt(scanner.nextLine());
- int pieces = widthCake * lengthCake;
- //стоп: 1.команда == Stop 2.pieces <= 0
- while (pieces > 0) {
- String command = scanner.nextLine(); //"STOP" или число (бр. взети парчета)
- if(command.equals("STOP")) {
- break;
- } else {
- //"5" -> число
- int takenPieces = Integer.parseInt(command); //взети парчета
- pieces -= takenPieces;
- }
- }
- if(pieces >= 0){
- //има останали парчета
- System.out.printf("%d pieces are left.", pieces);
- } else {
- //няма останали парчета -> pieces < 0
- System.out.printf("No more cake left! You need %d pieces more.", Math.abs(pieces));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement