码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-10-08 23:34:28      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

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 的嵌套 看着麻烦其实也没很麻烦,理顺逻辑顺序即可,个人感觉只要按部就班、严谨就好,人会取巧而使事态发展到别的方向,但计算机不会!
今天虽然只是复习,但感觉收获不少。

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

标签:

原文地址:http://www.cnblogs.com/shadow-wolf/p/5940272.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!