打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
V1.2跳转语句

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication4

{

    class Program

    {

        static void Main(string[] args)

        {

            /*-------------------------------    break 结束 -------------------------------*/

            Console.WriteLine("输出1-500的数字,每行10个");

            for (int i = 1; i < 501;i++ )

            {

                if ((i % 2 == 0) && (i % 3 == 0) && (i % 4 == 0) && (i % 5 == 0) && (i % 6 == 0) && (i % 7 == 0))

                {

                    Console.Write(i);

                    Console.WriteLine();

                    Console.WriteLine(i+" 就是我们想要的那个数");

                    break;

                }

                    //第10个数换行

                    if (i % 10 == 0)

                    {

                        Console.WriteLine(i);

                    }

                    else {

                        Console.Write(i+ " ");

                        if (i < 10) { Console.Write(" "); }

                        if (i < 100) { Console.Write(" "); }

                    }

            }

            /*-------------------------------    continue  跳出------------------------------*/

            Console.WriteLine("50以内的奇数有:");

            for(int i=0;i<51;i++){

                  //如果是偶数跳出

                  if (i%2==0){

                     continue ;   //continue  语句用于停止本次迭代 并非跳出迭代

                  }

              Console.WriteLine(i + "\t");   //"\t" 空格

            }

            /*-------------------------------   return   通过方法来实现------------------------------- */

            //while (true) {

                Console.WriteLine("请输入三个整数,按回车键确认每个数的输入");

                int a = int.Parse(Console.ReadLine());

                int b = int.Parse(Console.ReadLine());

                int c = int.Parse(Console.ReadLine());

                double average = (a + b + c) / 3;

                Console.WriteLine("请输入三个整数的平均值时:{0}",average);

                Console.ReadLine(); 

           //}

             /*------------------------------- go to 跳转-------------------------------*/

                int aa = 0;

                Console.WriteLine("5的阶乘等于几?根据以下选项选择正确的答案,回车键确认!");

                Console.WriteLine("1. 5!=5\n2.  5!=10\n3. 5!=20\n4. 5!=60 ");

            error:

                {

                    aa++;

                    if (aa > 1) { Console.WriteLine("很遗憾,你答错了,请重新输入答案!"); }

            }

            int option = int.Parse(Console.ReadLine());  // 接受输入的参数

            switch(option){

                case 1:

                case 2:

                case 3: goto error;

                case 4: goto right;

                default :

                    Console.WriteLine("您选择的选项不存在!");

                    goto end;

            }

        right:

            Console.WriteLine("恭喜你答对了");

        end:

            Console.ReadLine();

                /*------------------------------------------------------------------------*/

            Console.ReadKey();

        }

        static   double  avg (int a,int b,int c){

            return (a+b+c)/3;

        }

        }

    }

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
订票
控制语句
5-12undefined跳转语句之goto语句
C#基础知识系列一(goto、i++、三元运算符、ref和out、String和string、重载运算符)
C# 知识点 goto【学习笔记】
DOS计算器
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服