zoukankan      html  css  js  c++  java
  • /异常语句try,catch.

                //try//保护执行里面的代码段,若其中一句错误,直接跳转到catch,不会管下面的内容
                //{
                //    Console.WriteLine("请输入一个整数");
                //    int a = int.Parse(Console.ReadLine());
                //    Console.WriteLine("hello");
                //    break;
                //}
                //catch//
                //{
                //    Console.WriteLine("您的输入有误");
                
                
                //}
                //Console.ReadLine();
    
    
               //for与if  else的使用
    
                Console.WriteLine("你爱不爱我");
                
                for (int i = 1; i <= 3; i++)
                {
                    string a = Console.ReadLine();
                    if (a == "爱")
                    {
                        Console.WriteLine("我也爱你");
                        System.Threading.Thread.Sleep(2000);//单位:毫秒 
                        Console.WriteLine("从此王子和公主过上了没羞没臊的生活");
                        break;
                    }
                    else
                    {
                        if (i == 1)
                        {
                            Console.WriteLine("你爱不爱我");
                        }
                        if(i == 2)
                        {
                            Console.WriteLine("我问你,你到底爱不爱我");
                        }
                        if (i == 3)
                        {
                            Console.WriteLine("滚");
                        }
                        
                    }
    
                }
                Console.ReadLine();
    
    
    
                //请输入年月日,判断格式是不是正确
    
                //for (; ; )
                //{
                //    Console.WriteLine("请输入年份:");
                //    int y = int.Parse(Console.ReadLine());
                //    if (y >= 0 && y <= 9999)
                //    {
                //        for (; ; )
                //        {
                //            Console.WriteLine("请输入一个月份:");
                //            int m = int.Parse(Console.ReadLine());
                //            if (m > 0 && m <= 12)
                //            {
                //                for (; ; )
                //                {
                //                    Console.WriteLine("请输入一个日期:");
                //                    int d = int.Parse(Console.ReadLine());
                //                    if (d > 0 && d <= 31)
                //                    {
                //                        Console.WriteLine(y+ "年"  + m + "月" + d+ "日" );
                //                        break;
                //                    }
                //                    else
                //                    {
                //                        Console.WriteLine("您输入的日期有误");
                //                    }
                //                }
                //                break;
                //            }
                //            else
                //            {
                //                Console.WriteLine("您输入的月份有误");
                //            }
                //        }
                //        break;
                //    }
    
    
    
                //    else
                //    {
                //        Console.WriteLine("您的输入年份有误");
                //    }
                //}
                //    Console.ReadLine();
    
  • 相关阅读:
    CF676E:The Last Fight Between Human and AI
    BZOJ2079: [Poi2010]Guilds
    BZOJ4518: [Sdoi2016]征途
    BZOJ2216: [Poi2011]Lightning Conductor
    51nod1766 树上的最远点对
    洛谷P1257 平面上的最接近点对
    BZOJ2144: 跳跳棋
    BZOJ4773: 负环
    BZOJ4552: [Tjoi2016&Heoi2016]排序
    The Falling Leaves(建树方法)
  • 原文地址:https://www.cnblogs.com/xingfudehuanyan/p/5266413.html
Copyright © 2011-2022 走看看