zoukankan      html  css  js  c++  java
  • 判断年月日是否正确

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                 while (true)
                {
                    Console.Write("请输入年份:");
                    int year = int.Parse(Console.ReadLine());
                    Console.Write("请输入月份:");
                    int yue = int.Parse(Console.ReadLine());
                    Console.Write("请输入日期:");
                    int riqi = int.Parse(Console.ReadLine());
    
                    if (year > 0 && year < 9999)
                    {
                        if (yue == 1 || yue == 3 || yue == 5 || yue == 7 || yue == 8 || yue == 10 || yue == 12)
                        {
                            if (riqi > 0 && riqi <= 31)
                            {
                                Console.WriteLine("你输入的日期正确,请继续努力!");
                            }
                            else
                            {
                                Console.WriteLine("请输入正确的日期,谢谢。");
                            }
                        }
                        else if (yue == 4 || yue == 6 || yue == 9 || yue == 11)
                        {
                            if (riqi > 0 && riqi <= 30)
                            {
                                Console.WriteLine("你输入的日期正确,请继续努力!");
                            }
                            else
                            {
                                Console.WriteLine("请输入正确的日期,谢谢。");
                            }
                        }
                        else if (yue == 2)
                        {
                            if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
                            {
                                if (riqi > 0 && riqi <= 29)
                                {
                                    Console.WriteLine("你输入的日期正确,请继续努力");
                                }
                                else
                                {
                                    Console.WriteLine("请输入正确的日期,谢谢。");
                                }
                            }
                            else
                            {
                                if (riqi > 0 && riqi <= 28)
                                {
                                    Console.WriteLine("你输入的日期正确,请继续努力");
                                }
                                else
                                {
                                    Console.WriteLine("请输入正确的日期,谢谢。");
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("请输入正确的日期,谢谢。");
                        }
                    }
                    else
                    {
                        Console.WriteLine("请输入正确的日期,谢谢。");
                    }
                    Console.ReadLine();
                }
            }
        }
    }
  • 相关阅读:
    Mybatis多表查询
    (转)Java安全通信:HTTPS与SSL
    (转)RSA加密解密及数字签名Java实现
    (转)大型企业电话会议视频会议备份解决方案
    (转)虚拟IP原理
    虚拟IP---Linux下一个网卡配置多个IP
    C++ 点
    算法(8)Maximum Product Subarray
    算法(7)Majority Element II
    算法(6)3Sum Closest
  • 原文地址:https://www.cnblogs.com/qixinjian/p/4586026.html
Copyright © 2011-2022 走看看