Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine()), salary;
- String actor;
- while (budget >= 0 && !(actor = scanner.nextLine()).equals("ACTION")) {
- if (actor.length() <= 15) {
- salary = Double.parseDouble(scanner.nextLine());
- budget -= salary;
- } else {
- budget *= 0.8;
- }
- }
- if (budget < 0) {
- System.out.printf("We need %.2f leva for our actors.\n", Math.abs(budget));
- } else {
- System.out.printf("We are left with %.2f leva.\n", budget);
- }
- }
- }
- Решение с тернарен оператор и леко тарикатската:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- String actor;
- while (budget >= 0 && !(actor = scanner.nextLine()).equals("ACTION")) {
- budget = actor.length() <= 15 ? budget - Double.parseDouble(scanner.nextLine()) : budget * 0.8;
- }
- System.out.printf(budget < 0 ? "We need %.2f leva for our actors.\n" : "We are left with %.2f leva.\n", Math.abs(budget));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement