用户从键盘输入月份,使用switch语句输出该月份的天数

/*说在前面,为完成实验所写并保存记录,代码简单潦草,勿喷!*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PrintMonth
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入月份");
            int month = int.Parse(Console.ReadLine());
            switch (month) {
                case 1: {
                    Console.WriteLine(30);        
                    break; 
                }
                case 2: {
                    Console.WriteLine("请输入年份");
                    int year = int.Parse(Console.ReadLine());
                    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
                    {
                        Console.WriteLine(29);
                    }
                    else {
                        Console.WriteLine(28);
                    }
                    break;
                }
                case 3: {
                    Console.WriteLine(31);
                    break;
                }
                case 4:
                    {
                        Console.WriteLine(30);
                        break;
                    }
                case 5:
                    {
                        Console.WriteLine(31);
                        break;
                    }
                case 6:
                    {
                        Console.WriteLine(30);
                        break;
                    }
                case 7:
                    {
                        Console.WriteLine(31);
                        break;
                    }
                case 8:
                    {
                        Console.WriteLine(31);
                        break;
                    }
                case 9:
                    {
                        Console.WriteLine(30);
                        break;
                    }
                case 10:
                    {
                        Console.WriteLine(31);
                        break;
                    }
                case 11:
                    {
                        Console.WriteLine(30);
                        break;
                    }
                case 12:
                    {
                        Console.WriteLine(31);
                        break;
                    }
            
            }
            Console.ReadLine();
        }
    }
}


版权声明:本文为x_zhaohu原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。