完成以下要求:
{
Console.WriteLine("请输入年份");
int nian = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入月份");
int yue = Convert.ToInt32(Console.ReadLine());
if (yue >= 1 && yue <=12)
{
int ri = 0;
switch (yue)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
ri = 31;
break;
case 2:
if ((nian % 400 == 0) || (nian % 4 == 0 && nian % 100 != 0))
{
ri = 29;
}
else
{
ri = 28;
}
break;
case 4:
case 6:
case 9:
case 11:
ri = 30;
break;
default:
break;
}
Console.WriteLine("{0}年{1}月的天数是{2}",nian,yue,ri);
}
else
{
Console.WriteLine("请输入正确的月份!");
}
Console.ReadKey();
}
网友评论