- package com.yuxi.day0923;
- import java.util.ArrayList;
- import java.util.Random;
- public class DoubleBall {
- /*
- * 模拟双色球开奖:(红球:6个随机1-33之间的数字,红球不能重复。蓝球:1个随机1-16这间的数字)
- */
- public static void main(String[] args) {
- System.out.println(doubleball());
- }
- public static String doubleball()
- {
- ArrayList<Integer> db=new ArrayList<Integer>();
- Random rd=new Random();
- while(db.size()!=6)
- {
- int num=rd.nextInt(33)+1;
- if(!db.contains(num))
- {
- db.add(num);
- }
- }
- java.util.Collections.sort(db);
- StringBuilder sb=new StringBuilder();
- sb.append("红球: ");
- for(int i:db)
- {
- sb.append(i).append(" ");
- }
- db.add(rd.nextInt(16)+1);
- sb.append("蓝球: ").append(db.get(db.size()-1));
- return sb.toString();
- }
- }
复制代码
|
|