zoukankan      html  css  js  c++  java
  • SWITCH练习(一年第几天的判断)

    using System;
    namespace program
    {
        class program1
        {
            static void Main(string[] args)
            {
                program1 fenshu = new program1();
                fenshu.Panduan();
                program1 tian = new program1();
                tian.Tianshu();
            }
            /// <summary>
            /// 计算一年中的第几天
            /// </summary>
            void Tianshu()
            {
                Console.Write("请输入年份=");
                int a = Convert.ToInt32(Console.ReadLine());
                Console.Write("请输入月份=");
                int b = Convert.ToInt32(Console.ReadLine());
                Console.Write("请输入日=");
                int c = Convert.ToInt32(Console.ReadLine());
                int total = 365;
                if ((total % 4 == 0 && total % 100 != 0) || (total % 400 == 0))//是否闰年的判断
                {
                    total = 366;
                }
                switch (b)
                {
                    case 1: total -= 31; goto case 2;
                    case 2:
                        if ((total % 4 == 0 && total % 100 != 0) || (total % 400 == 0))//闰年二月份有29天                    
                            total -= 29;    //一层可以不使用块                
                        else                    
                            total -= 28;                    
                        goto case 3;
                    case 3: total -= 31; goto case 4;
                    case 4: total -= 30; goto case 5;
                    case 5: total -= 31; goto case 6;
                    case 6: total -= 30; goto case 7;
                    case 7: total -= 31; goto case 8;
                    case 8: total -= 31; goto case 9;
                    case 9: total -= 30; goto case 10;
                    case 10: total -= 31; goto case 11;
                    case 11: total -= 30; goto case 12;
                    case 12: total -= 31; goto default;
                    default: total += c; break;
                }
                Console.WriteLine("{0}年{1}月{2}日是一年的第{3}天", a, b, c, total);
            }
            /// <summary>
            /// 练习switch
            /// </summary>
            void Panduan()
            {
                Console.Write("请输入学生等级的值=");
                string a = Console.ReadLine();
                switch (a)
                {
                    case "A": Console.WriteLine("85-100"); break;
                    case "B": Console.WriteLine("70-84  "); break;
                    case "C": Console.WriteLine("60-69"); break;
                    case "D": Console.WriteLine("不及格"); break;
                    default: Console.WriteLine("输入有误"); break;
                }
            }
        }
    }
  • 相关阅读:
    玩转oracle学习第五天
    硅谷科技巨头最刁钻面试题集锦
    Python模拟登录wap版百度贴吧+自己主动回贴
    Flask 源代码阅读笔记
    Spark1.0.0 生态圈一览
    listView.getChildAt(i)时java.lang.NullPointerException
    选择排序
    JNI 系统钩子
    MySQL Cluster2个数据节点压力测试--mysqlslap工具压400W写
    VVDocumenter
  • 原文地址:https://www.cnblogs.com/BruceKing/p/11792291.html
Copyright © 2011-2022 走看看