Bachelor Party
Този while цикъл така и не го разбрах явно.... Само тази задача не успях да реша от пробния изпит. Ще се радвам да ми кажете къде бъркам.
public class BachelorParty { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int performerMoney = Integer.parseInt(scan.nextLine()); String command = scan.nextLine(); int count = 0; int pricePerGuest = 0; int diff = 0; int totalMoney = 0; while (!command.equals("The restaurant is full")) { int guests = Integer.parseInt(scan.nextLine()); if (guests < 5) { pricePerGuest = 100; } else { pricePerGuest = 70; } count = count + guests; totalMoney = pricePerGuest * count; diff = Math.abs(totalMoney - performerMoney); } if (diff < performerMoney) { System.out.printf("You have %d guests and %d leva left.", count, diff); } else { System.out.printf("You have %d guests and %d leva income, but no singer.", count, totalMoney); } } }