Advertisement
Spocoman

Movie Stars

Sep 8th, 2024
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double budget = Double.parseDouble(scanner.nextLine()), salary;
  7.         String actor;
  8.  
  9.         while (budget >= 0 && !(actor = scanner.nextLine()).equals("ACTION")) {
  10.  
  11.             if (actor.length() <= 15) {
  12.                 salary = Double.parseDouble(scanner.nextLine());
  13.                 budget -= salary;
  14.             } else {
  15.                 budget *= 0.8;
  16.             }
  17.         }
  18.  
  19.         if (budget < 0) {
  20.             System.out.printf("We need %.2f leva for our actors.\n", Math.abs(budget));
  21.         } else {
  22.             System.out.printf("We are left with %.2f leva.\n", budget);
  23.         }
  24.     }
  25. }
  26.  
  27. Решение с тернарен оператор и леко тарикатската:
  28.  
  29. import java.util.Scanner;
  30.  
  31. public class Main {
  32.     public static void main(String[] args) {
  33.         Scanner scanner = new Scanner(System.in);
  34.         double budget = Double.parseDouble(scanner.nextLine());
  35.         String actor;
  36.  
  37.         while (budget >= 0 && !(actor = scanner.nextLine()).equals("ACTION")) {
  38.             budget = actor.length() <= 15 ? budget - Double.parseDouble(scanner.nextLine()) : budget * 0.8;
  39.         }
  40.  
  41.         System.out.printf(budget < 0 ? "We need %.2f leva for our actors.\n" : "We are left with %.2f leva.\n", Math.abs(budget));
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement