判断年月日是否正确


//输入年月日
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();

posted @ 2015-06-02 15:13  微笑范特西  阅读(250)  评论(0编辑  收藏  举报