zoukankan      html  css  js  c++  java
  • 4、switch case 语句

    Switch case 语句

    输入一个年月日,判断是这一年的第几天?

                Console.WriteLine("请输入年:");

                int year = int.Parse(Console.ReadLine());

                Console.WriteLine("请输入月:");

                int month = int.Parse(Console.ReadLine());

                Console.WriteLine("请输入日:");

                int day = int.Parse(Console.ReadLine());

                int sum=0;

                if ((year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0)))

                {

                    switch (month)

                    {

                        case 1:

                            sum =day;

                            break;

                        case 2:

                            sum =day + 31;

                            break;

                        case 3:

                            sum =day + 31 + 29;

                            break;

                        case 4:

                            sum =day + 31 + 29 + 31;

                            break;

                        case 5:

                            sum =day + 31 + 29 + 31 + 30;

                            break;

                        case 6:

                            sum =day + 31 + 29 + 31 + 30 + 31;

                            break;

                        case 7:

                            sum =day + 31 + 29 + 31 + 30 + 31 + 30;

                            break;

                        case 8:

                            sum =day + 31 + 29 + 31 + 30 + 31 + 30 + 31;

                            break;

                        case 9:

                            sum =day + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31;

                            break;

                        case 10:

                            sum =day + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30;

                            break;

                        case 11:

                            sum =day + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;

                            break;

                        case 12:

                            sum =day + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;

                            break;

                        default:

                            Console.WriteLine("输入错误");

                            break;

                    }

                }

                else

                {

                    switch (month)

                    {

                        case 1:

                            sum =day;

                            break;

                        case 2:

                            sum =day + 31;

                            break;

                        case 3:

                            sum = day + 31 + 28;

                            break;

                        case 4:

                            sum =day + 31 + 28 + 31;

                            break;

                        case 5:

                            sum =day + 31 + 28 + 31 + 30;

                            break;

                        case 6:

                            sum =day + 31 + 28 + 31 + 30 + 31;

                            break;

                        case 7:

                            sum =day + 31 + 28 + 31 + 30 + 31 + 30;

                            break;

                        case 8:

                            sum =day + 31 + 28 + 31 + 30 + 31 + 30 + 31;

                            break;

                        case 9:

                            sum =day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;

                            break;

                        case 10:

                            sum =day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;

                            break;

                        case 11:

                            sum =day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;

                            break;

                        case 12:

                            sum =day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;

                            break;

                        default:

                            Console.WriteLine("输入错误");

                            break;

                    }

                }

     

                Console.WriteLine("这是{0}年的第{1}天",year,sum);

  • 相关阅读:
    Sphinx安装流程及配合PHP使用经验
    使用HTML5视频事件示例
    Centos6.5下编译安装mysql 5.6
    AES加密
    ab参数详解 – 压力测试
    vim 常用快捷键
    telnet操作memcache
    如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
    array_map 巧替 foreach
    mac brew安装mysql
  • 原文地址:https://www.cnblogs.com/XMH1217423419/p/4158309.html
Copyright © 2011-2022 走看看