Console.WriteLine("请输入年份");
string year = Console.ReadLine();
int nianfen = Convert.ToInt32(year);
Console.WriteLine("请输入月份");
string month = Console.ReadLine();
int yuefen = Convert.ToInt32(month);
if (yuefen>=1&&yuefen<=12)
{
int day = 0;
switch (yuefen)
{
case 1:
day = 31;
break;
case 3:
day = 31;
break;
case 5:
day = 31;
break;
case 7:
day = 31;
break;
case 8:
day = 31;
break;
case 10:
day = 31;
break;
case 12:
day = 31;
break;
case 2:
if ((nianfen % 400 == 0) || (nianfen % 4 == 0 && nianfen % 100 != 0))
{
day = 29;
}
else
{
day = 28;
}
break;
default:
day = 30;
break;
}
Console.WriteLine("{0}年{1}月有{2}天", nianfen, yuefen, day);
}
else
{
Console.WriteLine("月份必须在1~12月之间!程序退出!!!");
}
Console.ReadKey();
}