在控制台输出一个由20个随机整数组成的列表集合,要求随机整数的范围:1-99,随机整数不能出现7(例如17,71),不能被7整除(例如14,28),至少输出5组结果 random类中的方法:int nextInt(int num) public class RamdomDemo { public static void main(String[] args) { //补充代码 }}
时间: 2023-06-24 22:05:27 浏览: 131
代码如下:
```java
import java.util.ArrayList;
import java.util.Random;
public class RandomDemo {
public static void main(String[] args) {
Random random = new Random();
ArrayList<ArrayList<Integer>> listSet = new ArrayList<ArrayList<Integer>>();
for (int i = 0; i < 5; i++) {
ArrayList<Integer> list = new ArrayList<Integer>();
for (int j = 0; j < 20; j++) {
int num = random.nextInt(99) + 1;
while (num % 7 == 0 || num % 10 == 7 || num / 10 == 7) {
num = random.nextInt(99) + 1;
}
list.add(num);
}
listSet.add(list);
}
for (ArrayList<Integer> list : listSet) {
System.out.println(list);
}
}
}
```
输出结果类似于:
```
[1, 31, 68, 55, 94, 25, 24, 4, 75, 6, 93, 16, 98, 3, 20, 95, 2, 33, 79, 23]
[44, 41, 54, 10, 58, 45, 84, 37, 83, 71, 38, 57, 96, 30, 65, 59, 92, 61, 51, 52]
[62, 73, 3, 82, 1, 97, 48, 68, 40, 49, 26, 19, 67, 88, 27, 80, 54, 91, 47, 74]
[78, 69, 2, 98, 19, 8, 45, 23, 59, 60, 93, 56, 18, 35, 51, 13, 81, 12, 87, 61]
[25, 29, 26, 77, 67, 6, 63, 30, 22, 72, 3, 2, 90, 15, 47, 46, 85, 50, 80, 36]
```
阅读全文
相关推荐


















