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());
- int overnights = Integer.parseInt(scanner.nextLine());
- double overnightPrice = Double.parseDouble(scanner.nextLine());
- int additionalCosts = Integer.parseInt(scanner.nextLine());
- if (overnights > 7) {
- overnightPrice *= 0.95;
- }
- budget -= overnightPrice * overnights + 0.01 * budget * additionalCosts;
- if (budget >= 0) {
- System.out.printf("Ivanovi will be left with %.2f leva after vacation.\n", budget);
- } else {
- System.out.printf("%.2f leva needed.\n", Math.abs(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());
- int overnights = Integer.parseInt(scanner.nextLine());
- double overnightPrice = Double.parseDouble(scanner.nextLine());
- int additionalCosts = Integer.parseInt(scanner.nextLine());
- budget -= overnightPrice * (overnights > 7 ? 0.95 : 1) * overnights + 0.01 * budget * additionalCosts;
- System.out.printf(
- (budget >= 0
- ? ("Ivanovi will be left with %.2f leva after vacation.\n")
- : ("%.2f leva needed.\n")), Math.abs(budget)
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement