zoukankan      html  css  js  c++  java
  • 0723循环语句

    一.复习(选择语句)

    首先复习昨天学习的if语句

     格式1   if(){}

     格式2  if(){} else{}

     如果if满足,走if
     如果if不满足,就一定走else

     格式3 if(){}else   if(){}    else{}   多选一

     格式4  if的嵌套

     ////现在几点了,输出时间
                //Console.Write("请输入时间:");
                //int a = int.Parse(Console.ReadLine());
                //if (a <= 12)
                //{
                //    Console.WriteLine("现在是:" + a + "am");
                //}
                //else
                //{
                //    Console.WriteLine("现在是:" + (a-12) + "pm");
                //}
                //Console.ReadLine();

                //输入一个年份,判断是否是闰年(能被4整除却不能被100整除的年份。世纪年份能被400整除的是闰年)
                //Console.Write("请输入一个年份:");
                //double a = double.Parse(Console.ReadLine());
                //if (a % 4 == 0 && a % 100 != 0 || a % 100 == 0)
                //{
                //    Console.WriteLine("您输入的是闰年!");
                //}
                //else
                //{
                //    Console.WriteLine("您输入的不是闰年!");
                //}
                //Console.ReadLine();

                //输入一个100以内的整数,判断整数
                //Console.Write("请输入一个100以内的整数:");
                //double a = double.Parse(Console.ReadLine());
                //if (a == 100)
                //{
                //    Console.WriteLine("您输入的是三位整数!");
                //}
                //else if(a>=10&&a<100)
                //{
                //    Console.WriteLine("您输入的是两位整数!");
                //}
                //else
                //{
                //    Console.WriteLine("您输入的是一位整数!");
                //}
                //Console.ReadLine();


                //输入学生姓名,输入考试成绩
                //若是100,【恭喜**,满分通过!】
                //若是大于等于80小于100.【**,你很优秀,请继续保持】
                //若是大于等于60小于80,【**成绩良好】
                //大于等于50小于60,【**就差一点点,下次一定要至少及格】
                //小于50【**你是笨蛋吗】
                //Console.Write("请输入您的姓名:");
                //string b = Console.ReadLine();
                //Console.Write("请输入您的成绩:");
                //double a = double.Parse(Console.ReadLine());
                //if (a >= 0 && a <= 100)
                //{
                //    if (a==100)
                //    {
                //        Console.WriteLine("恭喜"+b+",满分通过!");
                //    }
                //    else if(a<100&&a>=80)
                //    {
                //        Console.WriteLine(  b + ",你很优秀,请继续保持!");
                //    }
                //    else if (a < 80 && a >= 60)
                //    {
                //        Console.WriteLine(b + "成绩良好!");
                //    }
                //    else if(a>=50&&a<60)
                //    {
                //        Console.WriteLine(b + "就差一点点,下次一定要至少及格!");
                //    }
                //    else
                //    {
                //        Console.WriteLine( b + "你是笨蛋吗?");
                //    }
                //}
                //else
                //{
                //    Console.WriteLine("您的输入有误!");
                //}
                //Console.ReadLine();


                //有一组函数:y = x (x<1);y = 2x -1  (1<=x<10); y = 3x-11  (x>=10)。
                // 括号内是x的满足条件。
                // 实现功能,随意输入一个x值,输出y的值
                //Console.Write("请输入x的值:");
                //double x = double.Parse(Console.ReadLine());
                // if(x<1)
                // {
                //     Console.WriteLine("得到的y值为:"+x);
                // }
                // else if (x >= 1 && x < 10)
                // {
                //     Console.WriteLine("得到的y值为:" +(2*x-1));
                // }
                // else
                // {
                //     Console.WriteLine("得到的y值为:" +(3*x-11) );
                // }

                // Console.ReadLine();

                //4.相亲过程:你有房子么?你有钱么?你有能力么?
                // 【结婚吧】【先买房子在结婚】【先赚钱再买房子再结婚】都没有【拜拜~~】
                //Console.Write("你有房子吗?");
                //string a = Console.ReadLine();
                //if (a == "有")
                //{
                //    Console.WriteLine("结婚吧!");
                //}
                //else
                //{
                //    Console.Write("你有钱吗?");
                //    string b = Console.ReadLine();
                //    if (b == "有")
                //    {
                //        Console.WriteLine("先买房子再结婚。");
                //    }
                //    else
                //    {
                //     Console.Write("你有能力吗?");
                //     string c = Console.ReadLine();
                //     if (c == "有")
                //     {
                //         Console.WriteLine("先赚钱再买房子再结婚。");
                //     }
                //     else
                //     {
                //         Console.WriteLine("拜拜~");
                //     }
                //    }
                //}
                //Console.ReadLine();

                //方程ax2+bx+c=0;一元二次方程。求根
                //△=b2-4ac;若△<0方程无实根
                //若△>0,方程有两个不相同的实根x1   x2
                //若△=0,方程有两个相同的实根
                //Console.Write("请输入a的值:");
                //double a = double.Parse(Console.ReadLine());
                //Console.Write("请输入b的值:");
                //double b = double.Parse(Console.ReadLine());
                //Console.Write("请输入c的值:");
                //double c = double.Parse(Console.ReadLine());
                //double de=b*b-4*a*c;
                //if(a!=0)
                //{
                //    if (de > 0)
                //    {
                //        Console.WriteLine("此方程有两个不同实数根,分别为x1="+((-b-de)/(2*a))+"x2="+((-b+de)/(2*a)));
                //    }
                //    else if (de == 0)
                //    {
                //        Console.WriteLine("此方程有两个相同实数根,为x1=x2=" + ((-b - de) / (2 * a)));
                //    }
                //    else
                //    {
                //        Console.WriteLine("此方程没有实数根");
                //    }
                //}
                //else
                //{
                //    Console.WriteLine("此方程不是一元二次方程");
                //}

                //Console.ReadLine();


                //输入年月日,查看格式是否正确
                //Console.Write("请输入年份:");
                //int year = int.Parse(Console.ReadLine());
                // if(year>=0&&year<=9999)
                // {
                //     Console.Write("请输入月份:");
                //     int month=int.Parse(Console.ReadLine());
                //     if (month >= 0 && month <= 12)
                //     {
                //         Console.Write("请输入日期:");
                //         int day = int.Parse(Console.ReadLine());
                //         if (day >= 1 && day <= 31)
                //         {
                //           if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
                //           {
                //              Console.WriteLine("您输入的日期格式正确,日期为:"+year+"年"+month+"月"+day+"日。");
                //           }
                //           else if(month==4||month==6||month==9||month==11)
                //           {
                //               if (day == 31)
                //               {
                //                   Console.WriteLine("您输入的日期格式错误!");
                //               }
                //               else
                //               {
                //                   Console.WriteLine("您输入的日期格式正确,日期为:" + year + "年" + month + "月" + day + "日。");
                //               }
                //           }
                //           else if(month==2)
                //           {
                //               if (day < 30)
                //               {
                //                   if (day == 29)
                //                   {
                //                       if (year % 4 == 0 && year % 100 != 0 || year % 100 == 0)
                //                       {
                //                           Console.WriteLine("您输入的日期格式正确,日期为:" + year + "年" + month + "月" + day + "日。");
                //                       }
                //                       else
                //                       {
                //                           Console.WriteLine("您输入的日期格式错误!");
                //                       }
                //                   }
                //                   else
                //                   {
                //                       Console.WriteLine("您输入的日期格式正确,日期为:" + year + "年" + month + "月" + day + "日。");
                //                   }
                //               }
                //               else
                //               {
                //                   Console.WriteLine("您输入的日期格式错误!");
                //               }
                //           }
                //         }
                //         else
                //         {
                //             Console.WriteLine("您输入的日期有错!");
                //         }
                //     }
                //     else
                //     {
                //         Console.WriteLine("您输入的月份有错!");
                //     }
                // }
                // else
                // {
                //     Console.WriteLine("您输入的年份有错!");
                // }
                // Console.ReadLine();

                //标准体重:
                //男士体重=身高-100±3
                //女士体重=身高-110±3
                //Console.Write("请输入您的性别:");
                //string a = Console.ReadLine();
                //Console.Write("请输入您的身高:");
                //double b = double.Parse(Console.ReadLine());
                // Console.Write("请输入您的体重:");
                //double c = double.Parse(Console.ReadLine());
                //if(a=="男")
                //{
                //    if (c >= (b - 100 - 3) && c <= (b - 100 + 3))
                //    {
                //        Console.WriteLine("您的体重标准!");
                //    }
                //    else
                //    {
                //        if (c < (b - 100 - 3))
                //      {
                //          Console.WriteLine("您偏瘦!");
                //      }
                //      else
                //      {
                //          Console.WriteLine("您偏胖!");
                //      }
                //    }
                //}
                //else if (a=="女")
                //{
                //    if (c >= (b - 110 - 3) && c <= (b - 110 + 3))
                //    {
                //        Console.WriteLine("您的体重标准!");
                //    }
                //    else
                //    {
                //        if (c < (b - 110 - 3))
                //        {
                //            Console.WriteLine("您偏瘦!");
                //        }
                //        else
                //        {
                //            Console.WriteLine("您偏胖!");
                //        }
                //    }
                //}
                //else
                //{
                //    Console.WriteLine("您的输入有误!");
                //}
                //Console.ReadLine();

                //输入三个数,由小到大排列输出
                //Console.Write("请输入第一个数:");
                //double a = double.Parse(Console.ReadLine());
                //Console.Write("请输入第一个数:");
                //double b = double.Parse(Console.ReadLine());
                //Console.Write("请输入第一个数:");
                //double c = double.Parse(Console.ReadLine());
                //double d;
                //if(a>=b)
                //{
                //    d = a;
                //    if (d >=c)
                //    {
                //        if (c >=b)
                //        {
                //            Console.WriteLine(a + ">" + c + ">" + b);
                //        }
                //        else
                //        {
                //            Console.WriteLine(a + ">" + b + ">" + c);
                //        }
                //    }
                //    else
                //    {
                //            Console.WriteLine(c + ">" + a + ">" + b);
                //        }
                //}
                //else
                //{
                //    d = b;
                //    if (d >=c)
                //    {
                //        if (a >= c)
                //        {
                //            Console.WriteLine(b + ">" + a + ">" + c);
                //        }
                //        else
                //        {
                //            Console.WriteLine(b + ">" + c + ">" + a);
                //        } 
                //    }
                //    else
                //    {
                //        Console.WriteLine(c + ">" + b + ">" + a);
                //    }
                //}
                //Console.ReadLine();
     

     二.循环语句

    for(;;){}

     //语句的分类:顺序,分支,循环语句
                 //循环语句
                //for (int i=1;i<=10 ;i++ )
                //{
                //    Console.WriteLine("你好!");
                //}
                //Console.ReadLine();

                ////死循环
                ////for (; ; )
                ////{
                ////     Console.WriteLine("nihao");
                ////}


                //输入一个正整数n,求1-n的和
                //Console.Write("请输入一个正整数:");
                //int a = int.Parse(Console.ReadLine());
                //int b = 0;
                //for (int i = 1; i <= a; i++)
                //{
                //    b = b + i; //b+=i;
                //}
                //Console.WriteLine(b);
                //Console.ReadLine();

                // 输入一个数,求阶乘
                //Console.Write("请输入一个正整数:");
                //int a = int.Parse(Console.ReadLine());
                //int b = 1;
                //for (int i = 1; i <= a; i++)
                //{
                //    b *= i;
                //}
                //Console.WriteLine(b);
                //Console.ReadLine();


                // 输入一个数,求阶乘的和
                //Console.Write("请输入一个正整数:");
                //int a = int.Parse(Console.ReadLine());
                //int b = 1; int c=0;
                //for (int i = 1; i <= a; i++)
                //{
                //    b *= i;
                //    if(i==4) //不进行4!
                //    {
                //        continue;//终止本次循环,继续下次循环
                //    }
                //     c += b;
                //}
                //Console.WriteLine(c);
                //Console.ReadLine();

                if嵌套for    for嵌套if
                //一个游戏,前20关是每一关自身的分数,
                //21-30关每一关是10分
                //31-40关,每一关是20分
                //41-49关,每一关是30分
                //50关,是100分
                //输入你现在闯到的关卡数,求你现在拥有的分数
                //Console.Write("请输入您的关卡:");
                //int a = int.Parse(Console.ReadLine());
                //int b = 0;
                //if (a < 1 && a > 50)
                //{
                //    Console.WriteLine("您输入的关卡数有误!");
                //}
                //else
                //{
                //    if (a <= 20)
                //    {
                //        for (int i = 1; i <= a; i++)
                //        {
                //            b += i;
                //        }
                      
                //    }
                //    else if (a >= 21 && a <= 30)
                //    {
                //        for (int i = 1; i <= 20; i++)
                //        {
                //            b += i;
                //        }
                //        for (int i = 21; i <= a; i++)
                //        {
                //            b += 10;
                //        }
                       
                //    }
                //    else if (a >= 31 && a <= 40)
                //    {
                //        for (int i = 1; i <= 20; i++)
                //        {
                //            b += i;
                //        }
                //        for (int i = 21; i <= 30; i++)
                //        {
                //            b += 10;
                //        }
                //        for (int i = 31; i <= a; i++)
                //        {
                //            b += 20;
                //        }
                      
                      
                //    }
                //    else if (a >= 41 && a <= 49)
                //    {
                //        for (int i = 1; i <= 20; i++)
                //        {
                //            b += i;
                //        }
                //        for (int i = 21; i <= 30; i++)
                //        {
                //            b += 10;
                //        }
                //        for (int i = 31; i <= 40; i++)
                //        {
                //            b += 20;
                //        }
                //        for (int i = 41; i <= 49; i++)
                //        {
                //            b += 30;
                //        }
                      
                //    }
                //    else
                //    {
                //          for (int i = 1; i <= 20; i++)
                //        {
                //            b += i;
                //        }
                //        for (int i = 21; i <= 30; i++)
                //        {
                //            b += 10;
                //        }
                //        for (int i = 31; i <= 40; i++)
                //        {
                //            b += 20;
                //        }
                //        for (int i = 41; i <= 49; i++)
                //        {
                //            b += 30;
                //        }
                //        b += 100;
                //    }
                //}
                //    Console.WriteLine(b);
                //    Console.ReadLine();


                //Console.Write("请输入您的关卡:");
                //int a = int.Parse(Console.ReadLine());
                //int b = 0;
                //if (a < 1 && a > 50)
                //{
                //    Console.WriteLine("您输入的关卡数有误!");
                //}
                //else
                //{
                //    for (int i = 1; i <= a; i++)
                //    {
                //        if (i <= 20)
                //        {
                //            b += i;
                //        }
                //        else if ( i <= 30)
                //        {
                //            b += 10;
                //        }
                //        else if ( i <= 40)
                //        {
                //            b += 20;
                //        }
                //        else if ( i <= 49)
                //        {
                //            b += 30;
                //        }
                //        else
                //        {
                //            b = b + 100;
                //        }
                //    }
                //}
                //Console.WriteLine("您的分数是:" + b);
                //Console.ReadLine();

                 //案例:找出100以内与7有关的数并打印、
                 //(1).从1找到100
                 //(2).找出与7有关的数
                 //      个位数是7 a%10==7
                 //      十位数是7 a/10 ==7
                 //      能被7整除 a%7 ==0
                //for (int i=1;i<=100&&i>0;i++)
                //{
                //    if (i % 10 == 7 )
                //    {
                //        Console.WriteLine(i+"个位数为7。");
                //    }
                //    else if (i / 10 == 7)
                //    {
                //        Console.WriteLine(i+"十位数为7。");
                //    }
                //    else if(i%7==0)
                //    {
                //        Console.WriteLine(i+"为7的倍数。");
                //    }
                //}
                //Console.ReadLine();
                //for (int i = 1; i <= 100 && i > 0; i++)
                //{
                //    if (i % 10 == 7||i / 10 == 7||i % 7 == 0)
                //    {
                //        Console.Write(i + " ");  //水平制表符
                //    }
                //}
                //Console.ReadLine();

  • 相关阅读:
    第11组(73) 需求分析报告
    第11组(73)团队展示
    结对编程作业
    第02组 Alpha冲刺 总结
    第02组 Alpha冲刺 (6/6)
    第02组 Alpha冲刺 (5/6)
    第02组 Alpha冲刺 (4/6)
    第02组 Alpha冲刺 (3/6)
    第02组 Alpha冲刺 (2/6)
    第02组 Alpha冲刺 (1/6)
  • 原文地址:https://www.cnblogs.com/a12110303043/p/5698886.html
Copyright © 2011-2022 走看看