Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace MonthPrinter
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- string print = "";
- switch (num)
- {
- case 1:
- print = "January";
- break;
- case 2:
- print = "February";
- break;
- case 3:
- print = "March";
- break;
- case 4:
- print = "April";
- break;
- case 5:
- print = "May";
- break;
- case 6:
- print = "June";
- break;
- case 7:
- print = "July";
- break;
- case 8:
- print = "August";
- break;
- case 9:
- print = "September";
- break;
- case 10:
- print = "October";
- break;
- case 11:
- print = "November";
- break;
- case 12:
- print = "December";
- break;
- default:
- print = "Error!";
- break;
- }
- Console.WriteLine(print);
- }
- }
- }
- With array and ternary operator:
- using System;
- namespace MonthPrinter
- {
- class Program
- {
- static void Main()
- {
- string[] month = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
- int num = int.Parse(Console.ReadLine());
- Console.WriteLine(num < 13 && num > 0 ? month[--num] : "Error!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement