• 利用switch case判断是今天的第多少天


    static void Main(string[] args)
            {
                while (true)
                {
                    int m1 = 31; int m2 = 28; int m3 = 31; int m4 = 30; int m5 = 31; int m6 = 30; int m7 = 31; int m8 = 31; int m9 = 30; int m10 = 31; int m11 = 30;
                  
                   
                    Console.Write("请输入月份");
                    int m = Convert.ToInt32(Console.ReadLine());
                    Console.Write("请输入几号");
                    int d = Convert.ToInt32(Console.ReadLine());
                    switch (m)      //若case1成立,则直接跳出switch的花括号,直接执行下一步。 switch后跟花括号,case与break必须连用,最后别忘了default与break的连用。。
                    {
                        case 1:
                            Console.Write("第"+d+"天");
                            break;
                        case 2:
                            Console.Write("第" +(m1+ d) + "天");
                            break;
                        case 3:
                            Console.Write("第" + (m1+m2+d) + "天");
                            break;
                        case 4:
                            Console.Write("第" + (m1+m2+m3+d) + "天");
                            break;
                        case 5:
                            Console.Write("第" + (m1+m2+m3+m4+d) + "天");
                            break;
                        case 6:
                            Console.Write("第" + (m1 + m2 + m3 + m4+m5 + d) + "天");
                            break;
                        case 7:
                            Console.Write("第" + (m1 + m2 + m3 + m4 + m5 +m6+ d) + "天");
                            break;
                        case 8:
                            Console.Write("第" + (m1 + m2 + m3 + m4 + m5 + m6+m7 + d) + "天");
                            break;
                        case 9:
                            Console.Write("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7+m8 + d) + "天");
                            break;
                        case 10:
                            Console.Write("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8+m9 + d) + "天");
                            break;
                        case 11:
                            Console.Write("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 +m9+m10+ d) + "天");
                            break;
                        case 12:
                            Console.Write("第" + (m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9 + m10+m11 + d) + "天");
                            break;
                        default:
                            Console.Write("输入有误");
                            break;

                    }

                    Console.ReadLine();
                }

  • 相关阅读:
    前端工程师们,这些干货让你开发效率加倍
    我的代码片段
    人生至少有一次为了自己的勇气而活
    美食篇之御桥小聚
    美食篇之好好对自己
    F
    Github 简明教程
    A
    完美字符串
    1222: FJ的字符串 [水题]
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4372874.html
Copyright © 2020-2023  润新知