AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > JAVA编程

JAVA版彩票随机生成系统

51自学网 2015-09-02 http://www.wanshiok.com

原帖及讨论:http://bbs.bccn.net/thread-108910-1-1.html

import java.io.*;
import java.util.Random;

class num
{
    public static void main(String[]args)
    {
        //声明一个随机数组
        int sjsh[]=new int[7];
        int sum;
        try
        {
            InputStreamReader a=new InputStreamReader(System.in);
            BufferedReader b=new BufferedReader(a);
            System.out.println ("欢迎使用齐鲁风采30选7彩票随机系统!");
            System.out.print ("请选择投注数:");
            String s=b.readLine();
            int sh=Integer.parseInt(s);
            //给随机数组赋随机值 且 保证没有重复
            for (int i = 0; i<sh; i++)
            {
                for (int j = 0; j<7; j++)
                {
                    Random rnd = new Random();
                    sjsh[j] = rnd.nextInt(31);
                    switch(j)
                    {
                        case 0:;break;
                        case 1:
                        {
                        if(sjsh[j]==sjsh[j-1])
                        j--;
                        };break;
                        case 2:
                        {
                        if(sjsh[j]==sjsh[j-1]||sjsh[j]==sjsh[j-2])
                        j--;
                        };break;
                        case 3:
                        {
                        if(sjsh[j]==sjsh[j-1]||sjsh[j]==sjsh[j-2]||sjsh[j]==sjsh[j-3])
                        j--;
                        };break;
                        case 4:
                        {
                        if(sjsh[j]==sjsh[j-1]||sjsh[j]==sjsh[j-2]||sjsh[j]==sjsh[j-3]||sjsh[j]==sjsh[j-4])
                        j--;
                        };break;
                        case 5:
                        {
                        if(sjsh[j]==sjsh[j-1]||sjsh[j]==sjsh[j-2]||sjsh[j]==sjsh[j-3]||sjsh[j]==sjsh[j-4]||sjsh[j]==sjsh[j-5])
                        j--;
                        };break;
                        case 6:
                        {
                        if(sjsh[j]==sjsh[j-1]||sjsh[j]==sjsh[j-2]||sjsh[j]==sjsh[j-3]||sjsh[j]==sjsh[j-4]||sjsh[j]==sjsh[j-5]||sjsh[j]==sjsh[j-6])
                        j--;
                        };break;
                    }
                }
                //冒泡排序
                for (int k = 0; k<7; k++)
                {
                    for (int j = 6; j>k; j--)
                    {
                        if(sjsh[j]<sjsh[j-1])
                        {
                        sum=sjsh[j];
                        sjsh[j]=sjsh[j-1];
                        sjsh[j-1]=sum;
                        }
                    }
                }
                for (int j = 0; j<7; j++)
                System.out.print (sjsh[j]+"/t");
                System.out.println ();
            }
        }
        catch (Exception ex)
        {
            System.out.println ("您的输入有错误!");
        }
    }
}

 

 

 
说明
:本教程来源互联网或网友上传或出版商,仅为学习研究或媒体推广,wanshiok.com不保证资料的完整性。
 
上一篇:JAVA版贪吃蛇  下一篇:巧用JAVASCRIPT代码限制文本字节数