用java编写一个辅助双色球选号的系统,红球从1~33中随机选出6个数,蓝球从1~16中随机选出1个数,且红球的

用java编写一个辅助双色球选号的系统,红球从1~33中随机选出6个数,蓝球从1~16中随机选出1个数,且红球的数不能有重复。总共选出这样的十注数

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
* 实现随机抽取,例如35选7等
*
* @author Administrator
*
*/

public class RandomSelect {

public static int[] randomSelect(int total, int number) {
int[] result = new int[number];
List<String> list = new ArrayList<String>();
Random r = new Random();

for (int i = 0; i < total; i++) {
list.add(i + 1 + "");
}

for (int j = 0; j < number; j++) {
int size = list.size();
String s = list.get(r.nextInt(size));

result[j] = Integer.parseInt(s);
list.remove(s);
}
return result;
}

public static void main(String[] args) {
int[] red = randomSelect(33, 6);
int[] blue = randomSelect(16, 1);
System.out.println("红球是:");
for (int i = 0; i < red.length; i++) {
System.out.print(red[i] + "\t");
}
System.out.println("\n蓝球是:");
for (int i = 0; i < blue.length; i++) {
System.out.println(blue[i] + "\t");
}
}

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-12-30

第2个回答  2021-01-04
郁结的心尘,如历经阴雨连追答

第3个回答  2010-10-18
同意上面的说法,要让你的帖子给 更多的人知道才好,真是黑啊!!
最好也能让CCTV来暴暴光!!!顶你!!!!
第4个回答  2010-10-12
我有写过,你不会叫我把代码给你贴出来吧?
相似回答