利用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();
            }

上一篇:JS数组添加字典的方法


下一篇:VFP自定义函数StringFormat (仿.NET String.Format 方法)