双色球

 1 import java.util.ArrayList;
 2 import java.util.Random;
 3 
 4 public class DoubleBall 
 5 {
 6   public static void main(String[] args) 
 7   {
 8     //1.创建33个球号
 9       String[]ballNumber= {"01","02","03","04","05","06","07","08","09","10","11","12"
10               ,"13","14","15","16","17","18","19","20","21","22","23","24","25","26","27"
11               ,"28","29","30","31","32","33"};
12         //2.创建容器
13       ArrayList put=new ArrayList();
14       //3.将球放入容器
15       for(int i=0;i<ballNumber.length;i++)
16       {
17           put.add(ballNumber[i]);
18       }
19       //4.创建篮球
20       String[]blue= {"01","02","03","04","05","06","07"};
21       //5.创建一个摇号数组--长度为6
22       String[]result=new String[6];
23       //6.创建随机数工具类
24       Random math=new Random();
25       //7.从容器中抽取六个红球号码
26       for(int j=0;j<result.length;j++)
27       {
28           int index=math.nextInt(put.size());//生成0~32的随机下标
29           result[j]=(String)put.get(index);//根据下标得到相应的球号
30           put.remove(index);//将被抽到的球号从数组中移除
31       }
32       //8.随机抽取一个篮球
33       String blueResult=blue[math.nextInt(blue.length)];
34       //9.打印
35       System.out.println("*********本期开奖************");
36       //遍历六个红球结果
37       for(int k=0;k<result.length;k++)
38       {
39           System.out.print("("+result[k]+") ");
40       }
41       System.out.println();
42       System.out.println("篮球开奖号: "+blueResult);
43       
44   }
45 }

 

posted @ 2018-12-13 20:18  静心*尽力  阅读(163)  评论(0编辑  收藏  举报