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(); } } } }
  • 相关阅读:
    (Java实现) 有重复元素排列问题
    玩转Google开源C++单元测试框架Google Test系列(转载)
    C++11之后,对源代码增加了UTF8和UCS4的支持(Windows内部使用Unicode,因为nt内核用的是ucs2,那是89年,utf8到了92年才发明出来)
    当年写的俄罗斯方块(现在更喜欢研究别人的代码)
    Stack的三种含义(数据超过栈的大小,就发生stack overflow)
    64位平台C/C++开发注意事项(转载)
    Redis集群方案
    Hadoop处理大量小文件的问题和解决方法
    Lazy Scheduler
    Solr与MongoDB集成,实时增量索引
  • 原文地址:https://www.cnblogs.com/zhengqian/p/6432821.html
Copyright © 2011-2022 走看看