Advertisement
Spocoman

07. Working Hours

Aug 25th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class  WorkingHours {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int hour = Integer.parseInt(scanner.nextLine());
  7.         String day = scanner.nextLine();
  8.  
  9.         if (hour >= 10 && hour <= 18) {
  10.             switch (day) {
  11.                 case "Monday":
  12.                 case "Tuesday":
  13.                 case "Wednesday":
  14.                 case "Thursday":
  15.                 case "Friday":
  16.                 case "Saturday":
  17.                     System.out.println("open");
  18.                     break;
  19.                 default:
  20.                     System.out.println("closed");
  21.                     break;
  22.             }
  23.         } else {
  24.             System.out.println("closed");
  25.         }
  26.     }
  27. }
  28.  
  29. ИЛИ:
  30.  
  31. import java.util.Arrays;
  32. import java.util.Scanner;
  33.  
  34. public class  WorkingHours {
  35.     public static void main(String[] args) {
  36.         Scanner scanner = new Scanner(System.in);
  37.         int hour = Integer.parseInt(scanner.nextLine());
  38.         String day = scanner.nextLine();
  39.  
  40.         String[] workingDays = new String[]{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  41.  
  42.         System.out.println(hour >= 10 && hour <= 18 && Arrays.toString(workingDays).contains(day) ? "open" : "closed");
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement