package com.neuedu.chapter4_1026;
public class Demo7 {
public static void main(String[] args) {
// 模拟35选7:在控制台打印7个1-35之间的数字,不能重复
// double d = Math.random();// [1,36)
// System.out.println(d);
boolean arr[] = new boolean[35];
for(int i = 0;i < 7;i++) {
int random = (int)(Math.random()*35+1);
// 判断是否生成过
if(arr[random-1]) {
i--;
}
else {
arr[random-1] = true;
System.out.print(random+" ");
}
}
}
}
网友评论