if else for练习

Posted Yao1101

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了if else for练习相关的知识,希望对你有一定的参考价值。

            for (int i =1;i<=3 ;i++ )
            {
                if (i == 1)
                {
                    Console.Write("你到底爱不爱我?");
                }
                if (i == 2)
                {
                    Console.Write("我问你呢,你到底爱不爱我?");
                }
                if (i == 3)
                {
                    Console.Write("你聋了么?我问你爱不爱我!!");

                }
                string a = Console.ReadLine();
                if (a == "爱")
                {
                    Console.WriteLine("嗯,我也爱你。");
                    System.Threading.Thread.Sleep(2000);
                    Console.WriteLine("从此王子和公主过上了没羞没臊的生活!");
                    break;
                }
                else
                {
                    if (i == 3)

                    {
                        Console.WriteLine("滚!");
                    }
                }
            }

 

            Console.Write(" 请输入年份:");
            for (; ; )
            {
                int a = int.Parse(Console.ReadLine());
                if (a >= 0 && a <= 9999)
                {  
                    Console.Write("请输入月份:");
                    for (; ; )
                    {
                        int b = int.Parse(Console.ReadLine());
                        if (b <= 12 && b > 0)

                        {
                            Console.Write("请输入日期:");
                            for (; ; )
                            {
                                int c = int.Parse(Console.ReadLine());
                                if (c > 0 && c <= 31)
                                {
                                    Console.WriteLine("你输入的格式" + a + "年," + b + "月," + c + "日,格式正确");
                                    break;
                                }
                                else
                                {
                                    Console.Write("你输入的日期错误,请从新输入:");

                                }
                            }
                            break;
                        }
                        else
                        {
                            Console.Write("你输入的月份错误,请重新输入:");
                        }
                    }
                    break;
                }
                else

                {
                    Console.Write("你输入的年份错误,请重新输入:");
                }
            }

 

以上是关于if else for练习的主要内容,如果未能解决你的问题,请参考以下文章

for循环练习

给段java里的if条件和if else 代码 练习练习

实验六——循环结构程序练习总结

python练习-if-else-or

python练习-if-elif-else

python练习-if-else-and