unity游戏开发-C#语言基础篇(bool值应用(开关))

  static void Main(string[] args)
        {
        //----------判断是不是素数-----------
        chongfu:
            int shuru = Convert.ToInt32(Console.ReadLine());
            bool isOpen = false;
            if (shuru <= 1)
            {
                Console.WriteLine("输入非法");
                goto chongfu;
            }

            for (int i = 2; i < shuru / 2 + 1; i++)
            {
                if (shuru % i == 0)
                {
                    isOpen = true;
                    break;
                }
            }
            if (isOpen)
            {
                Console.WriteLine("不是素数");

            }
            else
            {
                Console.WriteLine("是素数");
            }
            goto chongfu;
        }
    }

你可能感兴趣的:(unity游戏开发-C#语言基础篇(bool值应用(开关)))