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();
                }
            }
        }
    }
  • 相关阅读:
    wnmpa或lnmpa 服务器搭建和原理
    windows 桌面图标 隐藏 小盾牌标志
    C# 执行 CMD 终极稳定解决方案
    比较两个object是否相等
    Microsoft Store 加载失败
    ORA-12514: TNS:监听程序当前无法识别连接描述符中请求的服务
    Win10安装gcc、g++、make
    通过proxifier实现酸酸乳全局代理
    C# 字母转数字
    html中设置锚点定位的几种常见方法(#号定位)
  • 原文地址:https://www.cnblogs.com/qixinjian/p/4586026.html
Copyright © 2011-2022 走看看