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

生成0-42之间的7个不重复的int值

时间:2018-01-02 23:35:17      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:pos   重复   set集合   public   out   bsp   bre   int   ash   

 1 public static void main(String[] args) {
      //set集合存储不重复无序的值
2 Set<Integer> set = new HashSet<Integer>(); 3 Random random = new Random(); 4 boolean panduan = true; 5 while (true) { 6 int z = random.nextInt(43);
          //set.add();返回boolean值
7 panduan = set.add(z); 8 if (!panduan) { 9 continue; 10 } 11 if (set.size() >= 7) { 12 break; 13 } 14 15 } 16 17 System.out.println(set); 18 19 }

 

生成0-42之间的7个不重复的int值

标签:pos   重复   set集合   public   out   bsp   bre   int   ash   

原文地址:https://www.cnblogs.com/lyb0103/p/8179203.html

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