int year = 0, month = 0, day = 0;
Console.WriteLine("请输入年份");
try
{
y = Convert.ToInt32(Console.ReadLine());
try
{
Console.WriteLine("请输入月份");
m = Convert.ToInt32(Console.ReadLine());
if (month >= 1 && month <= 12)
{
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 11:
day = 31;
break;
case 2:
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
{
day = 29;
}
else
{
day = 28;
}
break;
default:
day = 30;
break;
}//switch
Console.WriteLine("{0}年{1}月{2}日", year, month, day);
}//超出月份的 if
else
{
Console.WriteLine("超出月份");
}//超出月份的if
}//月份 try
catch
{
Console.WriteLine("输入的月份格式有误,请以整数为输入方式");
}
}// 年份try
catch
{
Console.WriteLine("输入的年份格式有误,请以整数为输入方式");
}