标签:boolean 小实例 size 输出 static repeat i++ length public
import java.util.Random;
//输出小于33的7个不相同的随机数
public class probability {
static Random random = new Random();
static int[] array = new int[7];
static int number;
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int i = 0; i < array.length - 1; i++) {
number = (random.nextInt(33)) + 1;
if (i != 0) {
while (isRepeat(i, number)) {
number = random.nextInt(33) + 1;
}
}
array[i] = number;
}
array[6] = (int) (Math.random() * 16) + 1;
for (int j : array) {
System.out.println(j);
}
}
public static boolean isRepeat(int size, int number) {
boolean reqeat = false;
for (int i = 0; i < size; i++) {
if (array[i] == number) {
reqeat = true;
break;
}
}
return reqeat;
}
}
标签:boolean 小实例 size 输出 static repeat i++ length public
原文地址:http://www.cnblogs.com/L-zhihua/p/5988212.html