码迷,mamicode.com
首页 > 其他好文 > 详细

产生不重复的数字

时间:2014-08-25 22:27:55      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:java   ar   sp   new   size   ad   c   as   print   

import java.util.HashSet;

public class Rand {

public Rand() {
  HashSet<Integer> hs=new HashSet<Integer>();//HashSet像集合一样,产生不重复的数字
  while(true){
    int a=(int)(Math.random()*100);
    if(a>0){
      hs.add(a);
    }
    if(hs.size()==13){
      break;
    }
  }
  System.out.println(hs);


}


public static void main(String[] args) {
  new Rand();

}

}

 

产生不重复的数字

标签:java   ar   sp   new   size   ad   c   as   print   

原文地址:http://www.cnblogs.com/123qw/p/3935963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!