当前位置:网站首页>Case - random numbers without repetition (HashSet and TreeSet)
Case - random numbers without repetition (HashSet and TreeSet)
2022-06-13 05:05:00 【Jason_ LH1024】


package com.it02;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
public class Demo {
public static void main(String[] args) {
//1. Create a collection object
// Set<Integer> set = new HashSet<Integer>();
Set<Integer> set = new TreeSet<Integer>();
//2. Create random objects
Random r = new Random();
//3. Judge whether the set length is less than 10
while (set.size()<10){
// Generate a random number and save it to the set
int number = r.nextInt(20)+1;
set.add(number);
}
//4. Ergodic set
for (Integer i: set) {
System.out.println(i);
}
}
}

边栏推荐
- Section 2 - branch and loop statements
- metaRTC4.0集成ffmpeg编译
- CMB's written test -- data analysis
- Ruoyi cloud startup tutorial (hand-held graphics)
- 135. distribute candy
- Shell variable learning notes
- Redis plus instructions
- C language learning log 10.10
- [multi thread programming] the future interface obtains thread execution result data
- Sampo Lock
猜你喜欢
随机推荐
lookup
1.2 differences caused by keywords
On switch() case statement in C language
[thread / multithread] execution sequence of threads
C language exercise 1
Luogu p1012 guess
2021TPAMI/图像处理:Exploiting Deep Generative Prior for Versatile Image Restoration and Manipulation
Flex布局自适应失效的问题
Clause 32: moving objects into closures using initialization capture objects
详解OpenCV的函数cv::add(),并附各种情况的示例代码和运行结果
RMQ、LCA
Chapter 14 introduction: memory operation API
Binary search and binary answer
【多线程编程】Future接口获取线程执行结果数据
Must know must know -c language keywords
语音信号分帧的理解
Mysql8.0.13 installation tutorial (with pictures)
CMB written test graphical reasoning
关于匿名内部类
Clause 27: alternatives to overloading with familiar universal reference types









