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();

        }

    }

}

posted @ 2016-05-03 12:40  一人饮酒醉(SeVen❤)  阅读(167)  评论(0编辑  收藏  举报