【2017-02-22】if语句 if语句的嵌套 及巩固练习------------练习补充

“请输入年份:”(1-9999)
“请输入月份:”(1-12)
“请输入日期:”(要判断大小月,判断闰年)
判断输入的时间日期是否正确

//输出“请输入年份:”判断(1-9999)
            //输出“请输入月份:”判断(1-12)
            //输出“请输入日期:”判断(大小月、闰年、不能是负数)
            Console.Write("请输入年份(1-9999):");
            int nf = Convert.ToInt32(Console.ReadLine());



            if (nf > 0 && nf < 9999)
            {
                Console.WriteLine("您输入的格式正确");
                Console.Write("请输入月份(1-12):");
                int yf = Convert.ToInt32(Console.ReadLine());
                if (yf > 0 && yf < 13)
                {
                    Console.WriteLine("您输入的格式正确");
                    Console.Write("请输入日期");
                    int rq = Convert.ToInt32(Console.ReadLine());
                    if (rq > 0 && nf % 400 == 0 && yf == 1 && yf == 3 && yf == 5 && yf == 7 && yf == 8 && yf == 10 && yf == 12)
                    {
                        Console.WriteLine("您输入的格式正确");
                    }
                    else if (nf % 4 == 0 && nf % 100 == 0)
                    {
                        Console.WriteLine("您输入的格式正确");
                    }
                    else
                    {
                        Console.WriteLine("您输入的格式有误");
                    }
                }
                else
                {
                    Console.WriteLine("您输入的格式有误");
                }
            }
            else
            {
                Console.WriteLine("您输入的格式有误");
            }















            Console.ReadLine();

标准体重//注意运算关系的变换
男士体重 = 身高 - 100 +-3
kg cm
女士体重 = 身高 - 110 +-3

//男士体重 = 身高 - 100 +-3
            //     kg        cm
            //女士体重 = 身高 - 110 +-3
            Console.Write("请输入您的性别(男/女):");
            string xb = Console.ReadLine();

            Console.Write("请输入您的体重(kg):");
            double tz = Convert.ToDouble(Console.ReadLine());

            Console.Write("请输入您的身高(cm):");
            double sg = Convert.ToDouble(Console.ReadLine());


            if (xb == "")
            {
                double n = tz - sg + 100;
                if (n <= 3 && n >= -3)
                {
                    Console.WriteLine("您的体重是标准体重");
                }
                else if (n > 3)
                {
                    Console.WriteLine("您需要减肥了");
                }
                else if (n < -3)
                {
                    Console.WriteLine("您需要增加营养");
                }
            }
            else if (xb == "")
            {
                double n1 = tz - sg + 110;
                if (n1 <= 3 && n1 >= -3)
                {
                    Console.WriteLine("您的体重是标准体重");
                }
                else if (n1 > 3)
                {
                    Console.WriteLine("您需要减肥了");
                }
                else if (n1 < -3)
                {
                    Console.WriteLine("您需要增加营养");
                }
            }

            else
            {
                Console.WriteLine("您输入的格式有误");
            }















            Console.ReadLine();

“请输入24小时制的时间:”
0-24 如果超出“时间输入有误”

11 - “上午11点”
14 - “下午2点”

6点前是“凌晨”
晚上10点后是“深夜”

//“请输入24小时制的时间:”
            //0-24 如果超出“时间输入有误”

            //11 - “上午11点”
            //14 - “下午2点”

            //6点前是“凌晨”
            //晚上10点后是“深夜”
            Console.Write("请输入24小时制的时间:");
            int sj = Convert.ToInt32(Console.ReadLine());


            if (sj < 0 && sj > 24)
            {
                Console.WriteLine("您输入的时间格式有误");
            }
            else if (sj > 0 && sj < 24)
            {
                if (sj < 6)
                {
                    Console.WriteLine("凌晨" + sj + "");
                }
                else if (sj < 12)
                {
                    Console.WriteLine("上午" + sj + "");
                }
                else if (sj > 22)
                {
                    Console.WriteLine("深夜" + (sj - 12) + "");
                }
                else
                {
                    Console.WriteLine("下午" + (sj - 12) + "");
                }
            }






            Console.ReadLine();
原文地址:https://www.cnblogs.com/hanqi0216/p/6430886.html