public class TestRandom{
public static void main(String[] args){
Random a=new Random();
int s[]=new int[5];
for (int i = 0; i < s.length;) {
s[i]=a.nextInt(10);
if(CheckRandom(s,s[i],i)){
System.out.println("第"+(i+1)+"个
随机数是:"+s[i]);
i++;
}
}
}
public static boolean CheckRandom(int c[],int t,int l){//检查生成的随机数是否存在与数组中
for (int i = 0; i < c.length; i++) {
if(c[i]==t&&l!=i){
return false;
}
}
return true;
}
}