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);
- String destination = scanner.nextLine(),
- dates = scanner.nextLine();
- int nights = Integer.parseInt(scanner.nextLine());
- double sumPerNight = 0;
- if (destination.equals("France")) {
- if (dates.equals("21-23")) {
- sumPerNight = 30;
- } else if (dates.equals("24-27")) {
- sumPerNight = 35;
- } else if (dates.equals("28-31")) {
- sumPerNight = 40;
- }
- } else if (destination.equals("Italy")) {
- if (dates.equals("21-23")) {
- sumPerNight = 28;
- } else if (dates.equals("24-27")) {
- sumPerNight = 32;
- } else if (dates.equals("28-31")) {
- sumPerNight = 39;
- }
- } else if (destination.equals("Germany")) {
- if (dates.equals("21-23")) {
- sumPerNight = 32;
- } else if (dates.equals("24-27")) {
- sumPerNight = 37;
- } else if (dates.equals("28-31")) {
- sumPerNight = 43;
- }
- }
- System.out.printf("Easter trip to %s : %.2f leva.\n", destination, sumPerNight * nights);
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String destination = scanner.nextLine(),
- dates = scanner.nextLine();
- int nights = Integer.parseInt(scanner.nextLine());
- double sumPerNight = 0;
- switch (destination) {
- case "France" -> {
- sumPerNight = switch (dates) {
- case "21-23" -> 30;
- case "24-27" -> 35;
- case "28-31" -> 40;
- default -> 0;
- };
- }
- case "Italy" -> {
- sumPerNight = switch (dates) {
- case "21-23" -> 28;
- case "24-27" -> 32;
- case "28-31" -> 39;
- default -> 0;
- };
- }
- case "Germany" -> {
- sumPerNight = switch (dates) {
- case "21-23" -> 32;
- case "24-27" -> 37;
- case "28-31" -> 43;
- default -> 0;
- };
- }
- }
- System.out.printf("Easter trip to %s : %.2f leva.\n", destination, sumPerNight * nights);
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String destination = scanner.nextLine(),
- dates = scanner.nextLine();
- int nights = Integer.parseInt(scanner.nextLine());
- double sumPerNight =
- destination.equals("France") ?
- (dates.equals("21-23") ? 30 : dates.equals("24-27") ? 35 : dates.equals("28-31") ? 40 : 0) :
- destination.equals("Italy") ?
- (dates.equals("21-23") ? 28 : dates.equals("24-27") ? 32 : dates.equals("28-31") ? 39 : 0) :
- destination.equals("Germany") ?
- (dates.equals("21-23") ? 32 : dates.equals("24-27") ? 37 : dates.equals("28-31") ? 43 : 0) : 0;
- System.out.printf("Easter trip to %s : %.2f leva.\n", destination, sumPerNight * nights);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement