首先是switch做的

 class Program
    {
        static void Main(string[] args)
        {/*
          题目要求:请用户输入年份,输入月份,输出该月的天数。
          思路:一年中月份的情况有三种。
          第一种:1,3,5,7,8,10,12月是31天。
          第二种:4,6,9,11月是30天。
          第三种:要判断年份是否是闰年,闰年2月29天。
          平年2月28天。判断公式:year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)。
          */
            Console.WriteLine("请输入任意年份");
            int year = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入任意月份");
            int month = Convert.ToInt32(Console.ReadLine());
            switch (month)//括号内跟的是要判断的表达式,结果必须是一个”值“(也就是一个确定的数)。
            {
                ://当switch中的表达式有多种相同结果时,可以把case依次列出,最后break。
                :
                :
                :
                :
                :
                :
                    Console.WriteLine("您输入的{0}年中的{1}月份有31天。", year, month);
                    break;
                ://case语句中嵌套了if——else的语句,来判断是否是闰年。
                     ==  || (year %  ==  && year %  != ))//判断闰年的表达式
                    {
                        Console.WriteLine("您输入的{0}年中的2月份有29天。", year);
                    }
                    else//不是闰年执行这里。
                    {
                        Console.WriteLine("您输入的{0}年中的2月份有28天。", year);
                    }
                    break;
                default ://case中剩余的情况就是月份是30天的。
                    Console.WriteLine("您输入的{0}年中的{1}月份有30天。", year);
                    break;
            }
            Console.ReadLine();
        }
    }
}

用if——else做的

   class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入一个年份。");
            int year = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入年份中的任意一个月份。");
            int month = Convert.ToInt32(Console.ReadLine());
             || month ==  || month ==  || month ==  || month ==  || month ==  || month == )
            {
                Console.WriteLine("{0}年的{1}月份有31天。",year,month);
            }
             || month ==  || month ==  || month == )
            {
                Console.WriteLine("{0}年的{1}月份有30天。", year, month);
            }
            else
            {
                 ==  || (year %  ==  && year %  != ))
                {
                    Console.WriteLine("{0}年的2月份有29天", year);
                }
                else
                {
                    Console.WriteLine("{0}年的2月份有28天",year);
                }
            }
            Console.ReadLine();
        }
    }
}

最新文章

  1. 解决 The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
  2. Spring 通过工厂配置Bean
  3. ThinkPHP中where()方法的使用
  4. Stupid Tower Defense
  5. mysql 操作指令笔记
  6. selenium webdriver启动IE浏览器失败的解决办法
  7. 大整数算法[11] Karatsuba乘法
  8. HDU4662+无
  9. 世界最大射电望远镜(Arecibo)用于探測地外文明
  10. 【C++基础之十四】函参的缺省
  11. leetcode:linked_list_cycle_II
  12. 使用element ui 日期选择器获取值后的格式问题
  13. Android的ProgressBar进度条-android学习之旅(三十一)
  14. 出错:Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'cn.mgy.mapper.UserMapper.findById'.
  15. strcpy_s和strcpy()
  16. JavaScript中的注释问题详解? 部分3
  17. 百度软件开发实习生c++方向面经(一面)
  18. nginx禁止未绑定域名访问返回444
  19. 00009 - cat、tail、head、tee、wc、sort文件操作和过滤
  20. MEAN 27

热门文章

  1. 杂谈SharpDx中的WIC组件——我们需要WIC的图片编码功能么?
  2. uva 558 tree(不忍吐槽的题目名)——yhx
  3. SQLConnect_ref.cpp
  4. windows下如何安装jira
  5. OpenCV 之 数字图像
  6. 利用Google Speech API实现Speech To Text
  7. 数据结构Java实现07----队列:顺序队列&顺序循环队列、链式队列、顺序优先队列
  8. Lua笔记(2)
  9. homepage左边的导航菜单怎么做的?
  10. 二叉树的遍历(递归,迭代,Morris遍历)