Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Y06cake {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int width = Integer.parseInt(scanner.nextLine());
- int lenght = Integer.parseInt(scanner.nextLine());
- int cakeSize = width * lenght;
- String input = scanner.nextLine();
- while (!input.equals("STOP")) {//Когато правим While: 1. ДА си сложим условието ако го знаем, инче ползваме True 2. Това което го четем отвън да го четем отново вътре - отново вход вътре - същуият.
- int piece = Integer.parseInt(input);//Парчета - преобразуваме стринг към int
- cakeSize -= piece;
- if (cakeSize < 0) {
- System.out.printf("No more cake left! You need %d pieces more.", Math.abs(cakeSize));// Math.abs за да не се получат отрицателе борй парчета.
- return;
- }
- input = scanner.nextLine();//
- }
- System.out.printf("%d pieces are left.", cakeSize);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment