Advertisement
Spocoman

01. Day of Week

Jan 20th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DayOfWeek
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] week = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
  10.             int day = int.Parse(Console.ReadLine());
  11.  
  12.             if (day > 0 && day < 8)
  13.             {
  14.                 Console.WriteLine(week[day - 1]);
  15.             }
  16.             else
  17.             {
  18.                 Console.WriteLine("Invalid day!");
  19.             }
  20.         }
  21.     }
  22. }
  23.  
  24. Тарикатско решение:
  25.  
  26. using System;
  27.  
  28. namespace DayOfWeek
  29. {
  30.     class Program
  31.     {
  32.         static void Main(string[] args)
  33.         {
  34.             int day = int.Parse(Console.ReadLine());
  35.  
  36.             Console.WriteLine(day >= 0 && day <= 7 ? new string[]{ "Invalid day!", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}[day] : "Invalid day!");
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement