月份天数对不对的作业,感觉这样最简单了。


Console.ReadLine("请输入年份,月份,天数");
int year = Convert.ToInt32(Console.ReadLine());
int month = Convert.ToInt32(Console.ReadLine());
int day = Convert.ToInt32(Console.ReadLine());
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
if(day==31)
{
Console.WriteLine("正确");
}
else
{
Console.WriteLine("错误");
}
}
else if (month ==4|| month == 6|| month == 9 || month == 11)
{
if (day == 31)
{
Console.WriteLine("正确");
}
else
{
Console.WriteLine("错误");
}


}
else if(month==2)
{
if (0 == year % 400 || 0 == year % 4 && 0 != year % 100)
{
if (day == 29)
{
Console.WriteLine("正确");
}
else
{
Console.WriteLine("错误");
}
}
else
{
if (day == 28)
{
Console.WriteLine("正确");
}
else
{
Console.WriteLine("错误");
}
}

}

原文地址:https://www.cnblogs.com/zzc134680/p/5388758.html