首页 > 其他 > 详细

判断年月日是否正确

时间:2015-06-02 16:56:06      阅读:65      评论:0      收藏:0      [点我收藏+]


//输入年月日
Console.Write("请输入年:");
int year = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入月:");
int month = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入日:");
int day = Convert.ToInt32(Console.ReadLine());


if ((year % 4 == 0 && year % 100 != 0) || (year % 100 == 0 && year % 400 == 0))
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{

if (day >= 1 && day <= 31)
{
Console.WriteLine("正确");
}
else
{
Console.WriteLine("错误");
}


}

else if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (day >= 1 && day <= 30)
{
Console.WriteLine("正确");

}
else
{
Console.WriteLine("错误");
}

 

}

else
{
if (day >= 1 && day <= 29)
{
Console.WriteLine("正确");
}
else
{

Console.WriteLine("错误");
}

}


}

 

else
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
if (day >= 1 && day <= 31)
{
Console.WriteLine("正确");

}
else
{
Console.WriteLine("错误");
}


}

else if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (day >= 1 && day <= 30)
{
Console.WriteLine("正确");

}
else
{
Console.WriteLine("错误");
}


}

else
{
if (day >= 1 && day <= 28)
{
Console.WriteLine("正确");

}
else
{
Console.WriteLine("错误");

}

}

}

Console.ReadLine();

判断年月日是否正确

原文:http://www.cnblogs.com/weixiaofantasy/p/4546553.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!