• 4.28.FOR循环及其练习


    if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)

                        {

                            if (d <= 31 && d > 0)//日期输入正确

                            {

                                Console.WriteLine("日期输入正确!");

                                Console.WriteLine(y + "年" + m + "月" + d + "日");

                            }

                            else

                            {

                                Console.WriteLine("日期输入有误!");

                            }

                        }

                        else if (m == 4 || m == 6 || m == 9 || m == 11)//输入的是小月

                        {

                            if (d <= 30 && d > 0)//日期输入正确

                            {

                                Console.WriteLine("日期输入正确!");

                                Console.WriteLine(y + "年" + m + "月" + d + "日");

                            }

                            else

                            {

                                Console.WriteLine("日期输入有误!");

                            }

                        }

                        else if (m == 2)//如果是2月

                        {

                            //判断是否是闰年

                            //年份可以被4整除 并且 不能被100整除

                            //特殊年:或者,年份可以被400整除

                            if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)//说明当前是闰年

                            {

                                if (d <= 29 && d > 0)//日期正确

                                {

                                    Console.WriteLine("日期输入正确!");

                                    Console.WriteLine(y + "年" + m + "月" + d + "日");

                                    Console.WriteLine(y + "年是闰年!");

                                }

                                else//日期错误

                                {

                                    Console.WriteLine("日期输入有误!");

                                }

                            }

                            else//说明不是闰年

                            {

                                if (d <= 28 && d > 0)//日期正确

                                {

                                    Console.WriteLine("日期输入正确!");

                                    Console.WriteLine(y + "年" + m + "月" + d + "日");

                                    Console.WriteLine(y + "年不是闰年!");

                                }

                                else//日期错误

                                {

                                    Console.WriteLine("日期输入有误!");

                                }

                            }

                        }

                    }

                    else//月份错误

                    {

                        Console.WriteLine("月份输入有误!");

                    }

                }

                else//年份输入错误

                {

                    Console.WriteLine("年份输入有误!");

                }

     

                Console.ReadLine();

            }

        }

    }

  • 相关阅读:
    第五天
    第四天
    第三天
    四则运算2
    对于搜狗输入法
    用户及用户场景分析
    总结
    第一阶段总结
    第七天
    第六天
  • 原文地址:https://www.cnblogs.com/suiyuejinghao123/p/5454574.html
Copyright © 2020-2023  润新知