码迷,mamicode.com
首页 > 移动开发 > 详细

15-07-08 数组-- 手机号抽奖、福利彩票随机生成

时间:2015-07-16 00:44:53      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:

1.手机号抽奖

            Console.WriteLine("请输入手机号的个数:");
            int a = Convert.ToInt32(Console.ReadLine());

            string[] sj = new string[a];

            for (int i = 0; i < a; i++)
            {
                Console.WriteLine("请输入第{0}个手机号:", i + 1);
                sj[i] = Console.ReadLine();
            }
            Console.WriteLine("**********************");
            //抽奖
            DateTime t = DateTime.Now;
            DateTime tt = t.AddSeconds(10);
            while (true)
            {
                Console.Clear();
                Random r = new Random();
                int b = r.Next(a);

                Console.WriteLine(sj[b]);
                Thread.Sleep(60);

                if (DateTime.Now.ToString("yyyyMMddhhmmss") == tt.ToString("yyyyMMddhhmmss"))
                {
                    break;
                }
                else
                {

                }
            }
            Console.ReadLine();

 

 

2.福利彩票随机生成

Random n = new Random();
            int lan = n.Next(0,17);
            
            int [] hong=new int[6];

            int a = 0;
            while (true)
            {
                if (a == 6)
                {
                    break;
                }
                else
                {
                    int b = n.Next(0,34);
                    if (hong.Contains(b))
                    {
                    }
                    else
                    {
                        hong[a]=b;
                        a++;
                    }
                }
            }

                for (int i = 0; i < hong.Length - 1; i++)
                {
                    for (int j = 0; j < hong.Length - 1 - i; j++)
                    {
                        if (hong[j] >= hong[j + 1])
                        {
                            int zj = hong[j];
                            hong[j] = hong[j+1];
                            hong[j + 1] = zj;
                        }
                    }
                }
                Console.Write("红球为");
                for (int z = 0; z < a; z++)
                {
                    Console.Write(hong[z] + ",");
                }
                Console.WriteLine();
            Console.WriteLine("蓝球为"+lan);
        }

 

15-07-08 数组-- 手机号抽奖、福利彩票随机生成

标签:

原文地址:http://www.cnblogs.com/jia520110270/p/4649781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!