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种!

  • 相关阅读:
    Linux的ftp和www的服务器在虚拟机上的搭建
    Android中ViewPager
    Vue学习中踩的坑
    MySQL性能优化
    从Java内存模型讲双重检查锁原理
    JAVA8新特性学习
    JAVA中使用openoffice将Excel转PDF再转图片功能实现
    netty自定义协议上传
    poi-tl生成Word
    gitlab搭建
  • 原文地址:https://www.cnblogs.com/huaze/p/4031045.html
Copyright © 2011-2022 走看看