我一直ArrayIndexOutOfBoundsException
在说
winVals[i] = rand
,但我不知道为什么。
int valueCount = 5;
int theLimit = 5;
int[] winVals = new int[valueCount];
Random r = new Random();
int rand = 0;
for(int i= 0; i < winVals.length; i++)
{
rand = r.nextInt(theLimit - 1) +1;
if(i == 0)
{
winVals[0] = rand;
}
else if (i > 0)
{
for (int j = 0; j < winVals.length; j++)
{
if( winVals[j] == rand)
{
i--;
}
else
{
winVals[i] = rand;
}
}
}
}
for(int i=0; i < valueCount; i++)
{
System.out.println(winVals[i]);
}