Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class WorkingHours {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int hour = Integer.parseInt(scanner.nextLine());
- String day = scanner.nextLine();
- if (hour >= 10 && hour <= 18) {
- switch (day) {
- case "Monday":
- case "Tuesday":
- case "Wednesday":
- case "Thursday":
- case "Friday":
- case "Saturday":
- System.out.println("open");
- break;
- default:
- System.out.println("closed");
- break;
- }
- } else {
- System.out.println("closed");
- }
- }
- }
- ИЛИ:
- import java.util.Arrays;
- import java.util.Scanner;
- public class WorkingHours {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int hour = Integer.parseInt(scanner.nextLine());
- String day = scanner.nextLine();
- String[] workingDays = new String[]{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
- System.out.println(hour >= 10 && hour <= 18 && Arrays.toString(workingDays).contains(day) ? "open" : "closed");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement