码迷,mamicode.com
首页 > 其他好文 > 详细

作业1

时间:2014-12-22 21:14:11      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

输入年月日 验证

int year, mou, data;
Console.Write("请输入一个日期:年:");
string y = Console.ReadLine();
Console.Write("月:");
string m = Console.ReadLine();
Console.Write("日:");
string d = Console.ReadLine();
year = Convert.ToInt32(y);
mou = Convert.ToInt32(m);
data = Convert.ToInt32(d);
if ((year > 0000 & year < 9999) & (year % 4 != 0 || year % 400 != 0))
{
if ((mou > 0 & mou <= 12) & (mou == 1 || mou == 3 || mou == 5 || mou == 7 || mou == 8 || mou == 10 || mou == 12))
{
if (data > 0 & data <= 31)
{
Console.WriteLine("您输入的" + year + "年" + mou + "月" + data + "日是正确日期");
}
else if ((data > 0 & data <= 30) & (mou == 4 || mou == 6 || mou == 9 || mou == 11))
{
Console.WriteLine("您输入的" + year + "年" + mou + "月" + data + "日是正确日期");
if ((data > 0 & data <= 28) & (mou == 2))
{
Console.WriteLine("您输入的" + year + "年" + mou + "月" + data + "日是正确日期");
}
else
{
Console.WriteLine("您输入的日期错误");
}
}
else
{

Console.WriteLine("您输入的日期错误");
}

 

}
else
{
Console.WriteLine("您输入的日期错误");
}
}
else if ((year > 0000 & year < 9999) & (year % 4 == 0 & year % 100 != 0) || (year % 400 == 0))
{
if (mou == 2)
{
if (data > 0 & data <= 29)
{
Console.WriteLine("您输入的" + year + "年" + mou + "月" + data + "日是正确日期");
}
else
{
Console.WriteLine("您输入的日期错误");
}

}
else
{
Console.WriteLine("您输入的日期错误");
}
}
else
{
Console.WriteLine("您输入的日期错误");
}

作业1

标签:

原文地址:http://www.cnblogs.com/w297613932/p/4178883.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!