import java.util.HashSet;
import java.util.Random;
import java.util.Set;
/**
* 大乐透
* 需求:
* 前区从1-35之间取5个不重复的数字
* 后区从1-12之间取2个不重复的数字
* 取5组
* @author lijinyu
*
*/
public class DaLeTou1 {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
show();
}
}
private static void show() {
Set<Integer> set1 =new HashSet<>(); //前区集合
Set<Integer> set2 =new HashSet<>(); //后区集合
//前区从1-35取五个
while (set1.size()<5) {
int a =new Random().nextInt(35)+1;
set1.add(a);
}
System.out.println("前区为:");
System.out.println(set1);
//后区从1-12取两个n
while (set2.size()<2) {
int b=new Random().nextInt(12)+1;
set2.add(b);
}
System.out.println("后区为:");
System.out.println(set2);
}
}
Java大乐透
最新推荐文章于 2023-02-17 20:34:23 发布