集合随机抽取与排序(双色球)

来源:互联网 发布:java中最难的是什么 编辑:程序博客网 时间:2024/06/05 05:57
/*1.双色球投注时至少选择6个红球(1-33号)和一个蓝球(1-16号)。每注红球号不重复。
如:红球为 01 07 09 15 23 29  蓝球为08。
 。显示格式如:
第一注:红球: 01 07 09 15 23 29 蓝球: 08
第二注:红球: 01 05 09 19 23 29 蓝球: 04*/
public static void main(String[] args) {
List list=new ArrayList();
List list2=new ArrayList();

for(int i=01;i<34;i++){
list.add(i);

}
Collections.shuffle(list);
for(int j=1;j<=6;j++){
list2.add(list.get(j-1));
}
Collections.sort(list2);
for(Object o:list2){

if((int)o<10){
System.out.print("0"+o+"\t");
}else{
System.out.print(o+"\t");
}
}
int x=(int)(1+Math.random()*18);
if(x<10){
System.out.print("0"+x+"\t");
}else{
System.out.print(x+"\t");
}
}
0 0
原创粉丝点击