Advertisement
Spocoman

02. Weekend or Working Day

Aug 24th, 2024
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. import java.util.Objects;
  2. import java.util.Scanner;
  3.  
  4. public class WeekendOrWorkingDay {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         String day = scanner.nextLine();
  8.  
  9.         if (Objects.equals(day, "Monday")
  10.                 || Objects.equals(day, "Tuesday")
  11.                 || Objects.equals(day, "Wednesday")
  12.                 || Objects.equals(day, "Thursday")
  13.                 || Objects.equals(day, "Friday")) {
  14.             System.out.println("Working day");
  15.         } else if (Objects.equals(day, "Saturday")
  16.                 || Objects.equals(day, "Sunday")) {
  17.             System.out.println("Weekend");
  18.         } else {
  19.             System.out.println("Error");
  20.         }
  21.     }
  22. }
  23.  
  24. Решение със switch:
  25.  
  26. import java.util.Scanner;
  27.  
  28. public class WeekendOrWorkingDay {
  29.     public static void main(String[] args) {
  30.         Scanner scanner = new Scanner(System.in);
  31.         String day = scanner.nextLine();
  32.  
  33.         switch (day) {
  34.             case "Monday":
  35.             case "Tuesday":
  36.             case "Wednesday":
  37.             case "Thursday":
  38.             case "Friday":
  39.                 System.out.println("Working day");
  40.                 break;
  41.             case "Saturday":
  42.             case "Sunday":
  43.                 System.out.println("Weekend");
  44.                 break;
  45.             default:
  46.                 System.out.println("Error");
  47.                 break;
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement