C#语言,从键盘输入一个年份和一个月份,判断该月是多少天!

Console.WriteLine("请输入一个年份:");
int year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入一个月份:");
int month = Convert.ToInt32(Console.ReadLine());
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: Console.WriteLine("该月有31天!"); break;
case 4:
case 6:
case 9:
case 11: Console.WriteLine("该月有30天!"); break;
case 2:
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
Console.WriteLine("今年是闰年!有29天!");
}
else
{
Console.WriteLine("今年是平年!有28天!");
}
break;
default: Console.WriteLine("您输入的月份错误!"); break;
}

原文地址:https://www.cnblogs.com/Jasxu/p/3021937.html