Advertisement
IvanITD

02.WeekendorWorkDay

Jan 15th, 2024
750
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | Source Code | 0 0
  1. string dayOfWeek = Console.ReadLine();
  2.  
  3. // Firstly we will write the solution of this task with the if else statement
  4.  
  5. if (dayOfWeek == "Monday" || dayOfWeek == "Tuesday" || dayOfWeek == "Wednesday" || dayOfWeek == "Thursday" || dayOfWeek == "Friday")
  6. {
  7.     Console.WriteLine("Working day");
  8. }
  9. else if (dayOfWeek == "Saturday" || dayOfWeek == "Sunday")
  10. {
  11.     Console.WriteLine("Weekend");
  12. }
  13. else
  14. {
  15.     Console.WriteLine("Error");
  16. }
  17.  
  18.  
  19. // The second solution is with the switch case
  20.  
  21. switch (dayOfWeek)
  22. {
  23.     case "Monday":
  24.     case "Tuesday":
  25.     case "Wednesday":
  26.     case "Thursday":
  27.     case "Friday":
  28.         Console.WriteLine("Working day");
  29.         break;
  30.  
  31.     case "Saturday":
  32.     case "Sunday":
  33.         Console.WriteLine("Weekend");
  34.         break;
  35.         default:
  36.         Console.WriteLine("Error");
  37.             break;
  38.  
  39.  
  40.         //For this task we resolved the problem with two different solutions
  41. }
Tags: C#
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement