本帖最后由 zl78365336 于 2013-12-1 19:10 编辑
下面这个程序,打印的随机数个数不定,怎样固定输出个数呢?
--------------------------------------------------------
- public class Test {
- public static void main(String[] args) {
- System.out.println(getRandom());
- }
-
- public static Set<Integer> getRandom(){
- Random rd = new Random();
- Set<Integer> list = new HashSet<Integer>();
- for(int i=0;i<10;i++){
- int r = rd.nextInt(20)+1;
- list.add(r);
- }
- return list;
- }
- }
复制代码
|