//判断年月日是否正确; for (; ; ) { Console.Write("请输入年份:"); int a = int.Parse(Console.ReadLine()); if (a >= 0 && a <= 9999) { Console.Write("请输入月份:"); for (; ; ) { int b = int.Parse(Console.ReadLine()); if (b <= 12 && b > 0) { Console.Write("请输入日期"); for (; ; ) { int c = int.Parse(Console.ReadLine()); if (c > 0 && c <= 31) { if (b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12) { if (c > 0 && c <= 31) { Console.WriteLine("您输入的日期为" + a + "年" + b + "月" + c + "日"); break; } else { Console.Write("您输入的日期有误,请重新输入:"); } } if (b == 4 || b == 6 || b == 9 || b == 11) { if (c > 0 && c <= 30) { Console.WriteLine("您输入的日期为" + a + "年" + b + "月" + c + "日"); break; } else { Console.WriteLine("您输入的日期有误,请重新输入:"); } } if (b == 2) { if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0) { if (c > 0 && c <= 29) { Console.WriteLine("您输入的日期为" + a + "年" + b + "月" + c + "日"); break; } else { Console.WriteLine("您输入的日期有误,请重新输入:"); } } else { if (c > 0 && c <= 28) { Console.WriteLine("您输入的日期为" + a + "年" + b + "月" + c + "日"); break; } else { Console.WriteLine("您输入的日期有误,请重新输入:"); } } } } else { Console.WriteLine("您输入的日期有误,请重新输入:"); } } break; } else { Console.WriteLine("您输入的月份有误,请重新输入:"); } } break; } else { Console.WriteLine("您输入的年份有误,请重新输入:"); } } Console.ReadLine();
时间: 2024-10-19 02:28:16