DESKTOP-I6FA4UK_20200902-刘光超
1、问题
//33 选 7 再检测1000此 是否有重复
package cn.chao.sixty;
import java.util.Arrays;
import java.util.Random;
public class A57 {
//产生随机数
public int random() {
Random a = new Random();
int b = a.nextInt(33);
return b;
}
//比较产生的随机数是否与数组中书否有重复
public boolean select(int[] a,int x,int c) {
for (int y = 0; y < x; y++) {
if(a[y]==c) {
return false;
}
}
return true;
}
//确定数组各位的值
public static void mainx() {
A57 b = new A57();
int[] a = new int[7];
a[0] = b.random();
for (int x = 1; x < 7; x++) {
while (true) {
int c = b.random()+1;
if (b.select(a,x,c)) {
a[x] = c;
break;
}
}
}
System.out.println(Arrays.toString(a));
}
//返回数组中的数 为测试数组做准备
public int[] maint() {
A57 b = new A57();
int[] a = new int[7];
a[0] = b.random();
for (int x = 1; x < 7; x++) {
while (true) {
int c = b.random()+1;
if (b.select(a,x,c)) {
a[x] = c;
break;
}
}
}
return a;
}
//测试1000次产生的数组是否有相同的数子
public boolean test() {
int a =1000;
while(--a>0) {
int c[] =maint();
for(int x =0,n=c.length-1;x<n;x++) {
for(int y =0;y<n-1;y++) {
if(c[y]==c[y+1]) {
return false;
}
}
}
}
return true;
}
//输出代码
public static void resule() {
A57 b = new A57();
System.out.println("测试1000次数产生的数组");
if(b.test()) {
System.out.println("没有重复");
}else {
System.out.println("有重复");
}
}
public static void main(String[] args) {
mainx();
resule();
}
}
2、吐槽
无力吐槽。。。
点赞