zoukankan      html  css  js  c++  java
  • 语句(while/ do while / try catch finally)

       /* while

            int n = 1;                                         //此处如果是for循环,  for(int n=1;n<6;n++)

             while (n < 6)

                {     Console.WriteLine ("结果是{0}",n);    //留空的表示方法!

            // Console.Write("我是:{0},你是:{1},我们:{2}",a,b,c);       注意格式!  用,分隔,按顺序排列  。

                    n++;   //从n=1,递加!

                    if (n==6)

                    {

                        continue ;                               //跳出当前这一次循环,返回判断条件

                    }

                    if(n==9)

                    {

                          break;                                  //直接终止循环!

                    }

                }

                Console.ReadLine ();               */

      /*    //do  while        用法如下!

                int x = 0;
                do
                {
                    Console.WriteLine(x);    //先运行,再判断是否满足条件 !
                    x++;
                } while (x < 5);


                Console.ReadLine();          */

             

                try,catch,finally

                 try                              //试验{ }内容是否有错。
                {
                    int i = int.Parse(Console.ReadLine());
                    Console.WriteLine("这里是没有异常,可以打印!");
                }
                catch (Exception e)              //捉获错误!Exception表示在应用程序运行中发生的错误。
                {
                    Console.WriteLine("这里是错误了,请上报!");
                }
                finally                          //无论是否出现错误,都会运行!  
                {
                    Console.WriteLine("Thank You.");
                }
                Console.ReadLine();

    /* // 羽毛球拍15,羽毛球3,水2,一共200。//穷举法,得出符合条件的组合!

                     //13          66    100 

               int a =0;

              for (int x=1;x<=13;x++)

                 { 

                   for (int y=1;y<=66;y++)

                     {

                        for (int z=1;z<=100;z++)

                         {

                           if ( 15*x+3*y+2*z==200)    //判断是否符合条件的   if      语句!

                             {  a=++a;}

                            Console.WriteLine("pai" + x + "qiu" + y + "shui" + z);

                      //输出符合条件的组合的值!

                        }

                    }

                }

                 Console.Write ("zonggong"+a);//          a代表总共的组合个数!

                 Console.ReadLine();           */

    /*           //  2元,3元,5元找成50的!

                  //   25   16    10   (最大值)

                 int i=0;

                 for (int a = 0; a <= 25; a++)

                 {                 for (int b = 0; b <= 16; b++)

                     {                     for (int c = 0; c <= 10; c++)

                         {

                             if (2 * a + 3 * b + 5 * c == 50)

                             {                             i = ++i ;

                                 Console.WriteLine("A" + a + "B" + b + "C" + c);

                            }                      

                        }

                    }

                 }

                 Console.WriteLine("zonggong" + i);

                 Console.ReadLine();               */

        /*       //公鸡2元,母鸡1元,小鸡0.5元,每只最少一直,求100元买100 只鸡的所有可能

                 int a = 0;

                 for (int g = 1; g <= 50; g++)

                 {                 for (int m = 1; m <= 100; m++)

                     {                     for (int x = 1; x <= 200; x++)

                         {

                             if (2 * g + 1 * m + 0.5 * x == 100&&g+m+x==100)

                             {                             a = ++a;

                                        Console.WriteLine("G" + g + "M" + m + "X" + x);

                             }                 

                         }

                     }

                }

                Console.WriteLine("总共" + a);

                Console.ReadLine();              */   //33种!

  • 相关阅读:
    CSS优化压缩
    CSS clear both清除浮动总结
    jQuery下拉列表二级联动插件
    网站靠什么赚钱?
    程序员到高级程序员的职业生涯
    ie数组不支持indexOf 方法解决
    jquery中的each方法,$.each this.each $.fn.each
    css3写出0.5px的边框
    js 自己创建ready多个可以依次加载
    javascript中的removeEventListener失效问题
  • 原文地址:https://www.cnblogs.com/huaze/p/4031045.html
Copyright © 2011-2022 走看看