22,210
社区成员
发帖
与我相关
我的任务
分享
import java.util.*;
public class Test {
public static List<Integer> createRandom(int start, int end, int count) {
List<Integer> list = new LinkedList<>();
for (int number = start; number <= end; number++) {
list.add(number);
}
Collections.shuffle(list);
List<Integer> result = new ArrayList<>(count);
for (int i=0; i<count; i++) {
result.add(list.remove(0));
}
return result;
}
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.print("请输入要卖彩票的注数:");
int count = sc.nextInt();
for (int i=0; i<count; i++) {
List<Integer> random = createRandom(1, 35, count);
System.out.println(random);
}
}
}
}