1.生成5个整数并打印输出 2.生成5个double类型并打印输出 tip:Random类的种子需要设置为2022
时间: 2024-05-10 11:16:42 浏览: 22
下面是Java代码实现:
```java
import java.util.Random;
public class RandomDemo {
public static void main(String[] args) {
Random random = new Random(2022);
// 生成5个整数并打印输出
System.out.println("生成5个整数:");
for (int i = 0; i < 5; i++) {
int num = random.nextInt();
System.out.println(num);
}
// 生成5个double类型并打印输出
System.out.println("生成5个double类型:");
for (int i = 0; i < 5; i++) {
double num = random.nextDouble();
System.out.println(num);
}
}
}
```
输出结果:
```
生成5个整数:
-1434118120
-2043827751
-30782185
-1484102663
-1391903853
生成5个double类型:
0.8751180876577843
0.8542577600683122
0.139936913336764
0.9915640572275542
0.7044603435866196
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)