首页 > 代码库 > 假期结束------印象加深

假期结束------印象加深

Console.Write("请输入年份:");                 int y = int.Parse(Console.ReadLine());                 if (y > 0 && y <= 9999)                 {                     Console.Write("请输入月份:");                     int m = int.Parse(Console.ReadLine());                     if (m > 0 && m <= 12)                     {                         Console.Write("请输入日:");                         int d = int.Parse(Console.ReadLine());                         if (d > 0 && d <= 31)                         {                             if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)                             {                                 Console.WriteLine("您输入的日期为:{0}年{1}月{2}日", y, m, d);                             }                             else if (m == 4 || m == 6 || m == 9 || m == 11)                             {                                 if (d < 31)                                 {                                     Console.WriteLine("您输入的日期为:{0}年{1}月{2}日", y, m, d);                                 }                                 else                                 {                                     Console.WriteLine("你的输入有误!");                                 }                             }                             else                             {                                 if (d < 29)                                 {                                     Console.WriteLine("您输入的日期为:{0}年{1}月{2}日", y, m, d);                                 }                                 else if (d == 29 && (y % 4 == 0 && y % 100 != 0 || y % 400 == 0))                                 {                                     Console.WriteLine("您输入的日期为:{0}年{1}月{2}日", y, m, d);                                 }                                 else                                 {                                     Console.WriteLine("你的输入有误!");                                 }                             }                         }                         else                         {                             Console.WriteLine("你的输入有误!");                         }                     }                     else{                         Console.WriteLine("您输入的月份有误!");                     }                 }                 else                 {                     Console.WriteLine("您输入的年份有误!");                 }                 Console.ReadLine();
这题充分运用了if else 的嵌套 看着麻烦其实也没很麻烦,理顺逻辑顺序即可,个人感觉只要按部就班、严谨就好,人会取巧而使事态发展到别的方向,但计算机不会!
今天虽然只是复习,但感觉收获不少。

假期结束------印象加深