c# 编程 简单实现11个数中选择不重复出现的5个数。

来源:互联网 发布:python lxml 中文教程 编辑:程序博客网 时间:2024/05/16 19:51
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{    class Program    {        Random random = new Random();        public int[] ballNumber = new int[5];        public bool sign = false;        static void Main(string[] args)        {            new Program().shuangSeQiu();            Console.ReadKey();        }        #region shuang se qiu        public void shuangSeQiu()        {            for (int i = 0; i < 5; i++)            {                sign = false;                Console.WriteLine("the current count number is " + i);                int randomNumber = random.Next(1, 12);                Console.WriteLine("output: " + randomNumber);                if (i == 0)                {                    ballNumber[0] = randomNumber;                }                else                {                    for (int j = 0; j < i; j++)                    {                        if (randomNumber == ballNumber[j])                        {                            sign = true;                            i--;                            break;                        }                    }                    if (!sign)                    {                        ballNumber[i] = randomNumber;                    }                }            }            for (int i = 0; i < 5; i++)            {                Console.WriteLine(ballNumber[i]);            }        }        #endregion    }}

原创粉丝点击