あなたが私のコードのいくつかで私を助けることができるかどうか疑問に思っていました。私はこのパズルクリエータをプログラミングしていましたが、私の二次元配列の値を生成しようとすると、OutOfBoundsExceptionが発生します。私はこのソリューションは簡単だと確信していますが、何らかの理由で何が間違っているのか分からないようです。 (また、当然のことながら、そこにこれに沿って行くドライバーのクラスですが、私はそれがここに含める必要はないと思う。)2次元ループOutOfBoundsException - Java
import java.util.*;
public class ThirtyWonderful
{
private int dimen;
public ThirtyWonderful (int dimensions)
{
dimen = dimensions;
}
public ThirtyWonderful()
{
dimen = 5;
}
Random gen = new Random();
int[][] nums = new int [dimen][dimen];
public void genPuzzle()
{
for (int count = 0; count < dimen; count++)
{
for(int col = 0; col < dimen; col++)
{
nums[count][col] = gen.nextInt(9) + 1;
}
}
checkAcc();
if(checkAcc() == true)
{
for (int count = 0; count < dimen; count++)
{
for(int col = 0; col < dimen; col++)
{
System.out.print(nums[count][col] + " ");
}
System.out.println();
}
}
}
public boolean checkAcc()
{
int tot = 0;
for (int count = 0; count < dimen; count++)
{
for(int col = 0; col < dimen; col++)
{
tot += nums[count][col];
}
if(tot != 31)
return false;
}
for (int count = 0; count < dimen; count++)
{
for(int col = 0; col < dimen; col++)
{
tot += nums[count][col];
}
if(tot != 31)
return false;
}
return true;
}
}あなたは[新しいint型とNUMSを宣言している
例外はどこにありますか? – Guy