zoukankan      html  css  js  c++  java
  • 2017-2-23 C#基础 中间变量

    用中间变量做这个题

    1、“请输入年份:”(1-9999)
    “请输入月份:”(1-12)
    “请输入日期:”(要判断大小月,判断闰年)
    判断输入的时间日期是否正确

    2、计算输入的时间是当前这一年的第几天

    namespace _2017_2_23判断日期格式优化代码
    {
        class Program
        {
            static void Main(string[] args)
            {
                bool dateISOK = false;
                bool isRN = false;
                {
                    int year; int month = 0; int day = 0;int num=0;
                    Console.WriteLine("请输入年份:(1-9999)");
                    year = Convert.ToInt32(Console.ReadLine());
                    if (year >= 1 && year <= 9999)
                    {
                        if (year >= 1 && year <= 9999 && year % 4 == 0 && year % 100 != 0 || year % 400 == 0) 
                        {
                            isRN = true;
                        }
                        Console.WriteLine("请输入月份:");
                        month = Convert.ToInt32(Console.ReadLine());
                        if (month >= 1 && month <= 12)
                        {
                            Console.WriteLine("请输入日期:");
                            day = Convert.ToInt32(Console.ReadLine());
                            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 && day >= 1 && day<= 31)
                            {
                                Console.WriteLine("您输入的日期格式正确");
                                dateISOK = true;
                            
                              
                            }
    
                            else if ((month == 4 || month == 6 || month == 9 || month == 11) && day >= 1 && day <= 30)
                            {
                                Console.WriteLine("您输入的日期格式正确");
                                dateISOK = true;
                            
                            }
                            else if (isRN==true && month == 2 && day >= 1 && day <= 29)
                            {
                                Console.WriteLine("您输入的日期格式正确");
                                dateISOK = true;
                                isRN = true;
                            
                            }
                            else if (isRN==false && month == 2 && day >= 1 && day <= 28)
                            {
                                Console.WriteLine("您输入的日期格式正确");
                                dateISOK = true;
    
                            
                            }
    
    
                            else
                            {
                                Console.WriteLine("您输入的日期格式不对");
                            }
                        }
                        else
                        {
                            Console.WriteLine("您输入的月份格式错误");
                        }
                    }
                    else
                    {
                        Console.WriteLine("您输入的年份格式错了");
                    }
                    if(dateISOK==true&&month==1)
                    {
                        num = day;
                    }
                    if(dateISOK==true&&month==2)
                    {
                        num = 31 + day;
                    }
                    if(dateISOK==true&&month==3&&isRN==true)
                    {
                        num = 31 + 29 + day;
                    }
                    if(dateISOK==true&&month==3&&isRN==false)
                    {
                        num = 31 + 28 + day;
                    }
                    if (dateISOK == true && month == 4 && isRN == true)
                    {
                        num = 31 + 29 +31+ day;
                    }
                    if (dateISOK == true && month == 4 && isRN == false)
                    {
                        num = 31 + 28+31 + day;
                    }
                    if (dateISOK == true && month == 5 && isRN == true)
                    {
                        num = 31 + 29 + 31 +30+ day;
                    }
                    if (dateISOK == true && month ==5 && isRN == false)
                    {
                        num = 31 + 28 + 31 +30+ day;
                    }
                    if (dateISOK == true && month == 6 && isRN == true)
                    {
                        num = 31 + 29 + 31 + 30+31 + day;
                    }
                    if (dateISOK == true && month ==6 && isRN == false)
                    {
                        num = 31 + 28 + 31 + 30+31 + day;
                    }
                    if (dateISOK == true && month == 7 && isRN == true)
                    {
                        num = 31 + 29 + 31 + 30 + 31+30 + day;
                    }
                    if (dateISOK == true && month == 7 && isRN == false)
                    {
                        num = 31 + 28 + 31 + 30 + 31+30 + day;
                    }
                    if (dateISOK == true && month == 8 && isRN == true)
                    {
                        num = 31 + 29 + 31 + 30 + 31 + 30 +31+ day;
                    }
                    if (dateISOK == true && month == 8 && isRN == false)
                    {
                        num = 31 + 28 + 31 + 30 + 31 + 30+31 + day;
                    }
                    if (dateISOK == true && month == 9 && isRN == true)
                    {
                        num = 31 + 29 + 31 + 30 + 31 + 30 + 31+31 + day;
                    }
                    if (dateISOK == true && month ==9&& isRN == false)
                    {
                        num = 31 + 28 + 31 + 30 + 31 + 30 + 31 +31+ day;
                    }
                    if (dateISOK == true && month == 10 && isRN == true)
                    {
                        num = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31+30 + day;
                    }
                    if (dateISOK == true && month == 10 && isRN == false)
                    {
                        num = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31+30 + day;
                    }
                    if (dateISOK == true && month == 11 && isRN == true)
                    {
                        num = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 +31+ day;
                    }
                    if (dateISOK == true && month == 11 && isRN == false)
                    {
                        num = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 +31+ day;
                    }
                    if (dateISOK == true && month == 12 && isRN == true)
                    {
                        num = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 +30+ day;
                    }
                    if (dateISOK == true && month == 12&& isRN == false)
                    {
                        num = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 +30+ day;
                    }
    Console.WriteLine("你输入的日期是当年的第"+num+"天"); Console.ReadLine(); } } } }
  • 相关阅读:
    优雅的使用Python之软件管理
    优雅的使用python之环境管理
    SpriteSheet精灵动画引擎
    【译】AS3利用CPU缓存
    走在网页游戏开发的路上(十一)
    自定义路径创建Cocos2d-x项目
    C++静态库与动态库
    C++对象模型
    超时空英雄传说2复仇魔神完全攻略&秘技
    从头写个http client(java)
  • 原文地址:https://www.cnblogs.com/zhengqian/p/6432821.html
Copyright © 2011-2022 走看看