silviasj

cake

Apr 4th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Cake_06 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int width = Integer.parseInt(scanner.nextLine());
  8.         int length = Integer.parseInt(scanner.nextLine());
  9.  
  10.         int pieces = width * length;
  11.  
  12.         //СТОП: ако команда == "STOP" -> продължаваме: command != "STOP"
  13.         //СТОП: ако свърши тортата -> pieces <= 0
  14.  
  15.         String command = scanner.nextLine();// "STOP" или "брой парчета"
  16.  
  17.         while (!command.equals("STOP")){
  18.             //брой парчета -> "3" на int
  19.             int takenPieces = Integer.parseInt(command);
  20.             pieces -= takenPieces;
  21.             if(pieces <= 0){
  22.                 System.out.printf("No more cake left! You need %d pieces more.", Math.abs(pieces));
  23.                 break;
  24.             }
  25.  
  26.             command = scanner.nextLine();
  27.         }
  28.  
  29.         if(command.equals("STOP")){
  30.             System.out.printf("%d pieces are left.", pieces);
  31.         }
  32.  
  33.  
  34.     }
  35. }
Add Comment
Please, Sign In to add comment