首页 > 代码库 > 作业1
作业1
输入年月日 验证
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 = http://www.mamicode.com/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