我遇到下标超出范围的错误,以完成我在Java中的内存匹配游戏程序。这是一个6 x 6的木板,在坐标中具有随机数。我应该在第一个for循环中使用什么数字(cnt1 <=?)
public static int[][] shuffleHard()
{
int startHard[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
int cardsHard[][] = new int[100][100];
Random ran = new Random();
int hold, num =0 ;
for (int cnt1 = 0; cnt1 <= ?; cnt1++)
{
for (int cnt2 = 0; cnt2 < 36; cnt2++) //randomize the cards
{
cnt1 = ran.nextInt(10000) % 15;
hold = startHard[cnt2];
startHard[cnt2] = startHard[cnt1];
startHard[cnt1] = hold;
}
}
for (int cnt1 = 0; cnt1 < 6; cnt1++) // put values in places
{
for (int cnt2 = 0; cnt2 < 6; cnt2++)
{
cardsHard[cnt1][cnt2] = startHard[num];
num = num + 1;
}
}
return cardsHard;