Java随机数
能否用10次循环,将0~9的随机数全部产生出来..即每个数字出现一次.呵呵..
参考答案:int[] randoms = new int[10]{0,1,2,3,4,5,6,7,8,9};
Random rnd = new Random();
int x = 0;
int count = 0;
while(count != 10)
{
x = rnd.nextInt(9);
if(randoms[x] != -1)
{
System.out.println(randoms[x]);
randoms[x] = -1;
count ++;
}
}