Advertisement
desislava_topuzakova

Cake

Feb 9th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Cake1 {
  4.     public static void main(String[] agrs) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int width = Integer.parseInt(scanner.nextLine());
  7.         int length = Integer.parseInt(scanner.nextLine());
  8.         int allPieces = width * length; //колко парчета торта имаме
  9.         int totalPices = 0; //брои колко парчета сме взели
  10.         int leftPieces = 0; // остатък от парчета
  11.         for (int i = 0; i < allPieces; i++) {
  12.             String pieces = scanner.nextLine();
  13.            
  14.             if (!pieces.equals("STOP")) {
  15.                 totalPices += Integer.valueOf(pieces);
  16.                 leftPieces = allPieces - totalPices;
  17.                 if (leftPieces < 0) {
  18.                     System.out.printf("No more cake left! You need %d pieces more.", Math.abs(leftPieces));
  19.                     break;
  20.                 }
  21.  
  22.             } else {
  23.  
  24.                 leftPieces = Math.abs(allPieces - totalPices);
  25.                 System.out.printf("%d pieces are left.", leftPieces);
  26.                 break;
  27.             }
  28.         }
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement