現在のところ、このコードは完成していません。私は、各スペースに異なる1桁の数字を持つ3x3配列をランダムに生成するのに必要なメソッドを書いています。しかし、最初の行にはInternal compiler error: java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.ast.ReferenceExpression.copy(ReferenceExpression.java:141)
というエラーが表示されます。私は本当にこのエラーが何を意味するか分からない、私は繁栄プログラマーだから。このエラーを修正するにはどうすればよいですか?内部コンパイラエラー?
public class MagicSquare {
public static void main(String[] args) {
}
public static int sumRows(int[][] array) {
int totalRowOne;
int totalRowTwo;
int totalRowThree;
totalRowOne = array[0][0] + array[0][1] + array[0][2];
totalRowTwo = array[1][0] + array[1][1] + array[1][2];
totalRowThree = array[2][0] + array[2][1] + array[2][2];
if(totalRowOne == totalRowTwo && totalRowOne == totalRowThree) {
return totalRowOne;
}
else {
return -1;
}
}
public static int sumColumns(int[][] array) {
int totalColumnOne;
int totalColumnTwo;
int totalColumnThree;
totalColumnOne = array[0][0] + array[1][0] + array[2][0];
totalColumnTwo = array[0][1] + array[1][1] + array[2][0];
totalColumnThree = array[0][2] + array[1][2] + array[2][2];
if(totalColumnOne == totalColumnTwo && totalColumnOne == totalColumnThree) {
return totalColumnOne;
}
else {
return -1;
}
}
public static int sumDiagonals(int[][] array) {
int totalDiagonalOne;
int totalDiagonalTwo;
totalDiagonalOne = array[0][0] + array[1][1] + array[2][2];
totalDiagonalTwo = array[0][2] + array[1][1] + array[2][0];
if(totalDiagonalOne == totalDiagonalTwo) {
return totalDiagonalOne;
}
else {
return -1;
}
}
public static boolean isUnique(int[][] array, int num) {
if(num == array[0][0] || num == array[0][1] || num == array[0][2] ||
num == array[1][0] || num == array[1][1] || num == array[1][2] ||
num == array[2][0] || num == array[2][1] || num == array[2][2]) {
return true;
}
else {
return false;
}
}
public static void displayMagicSquare(int[][] array) {
int counter1;
int counter2;
for(counter1 = 0; counter1 < 3; counter1++) {
for(counter2 = 0; counter2 < 3; counter2++) {
System.out.print(array[counter1][counter2]);
}
System.out.print("/n");
}
}
public static int[][] fillMatrix(int[][] array) {
int numberOne;
int numberTwo;
int numberThree;
int numberFour;
int numberFive;
int numberSix;
int numberSeven;
int numberEight;
int numberNine;
array[0][0] = 0;
array[0][1] = 0;
array[0][2] = 0;
array[1][0] = 0;
array[1][1] = 0;
array[1][2] = 0;
array[2][0] = 0;
array[2][1] = 0;
array[2][2] = 0;
numberOne = (int)(Math.random() * 8 + 1);
do {
numberTwo = (int)(Math.random() * 8 + 1);
} while(numberTwo == numberOne);
do {
numberThree = (int)(Math.random() * 8 + 1);
} while(numberThree == numberTwo || numberThree == numberOne);
do {
numberFour = (int)(Math.random() * 8 + 1);
} while(numberFour == numberThree || numberFour == numberTwo || numberFour == numberOne);
do {
numberFive = (int)(Math.random() * 8 + 1);
} while (numberFive == numberFour || numberFive == numberThree || numberFive == numberTwo ||
numberFive == numberOne);
do {
numberSix = (int)(Math.random() * 8 + 1);
} while(numberSix == numberFive || numberSix == numberFour || numberSix == numberThree ||
numberSix == numberTwo ||numberSix == numberOne);
do {
numberSeven = (int)(Math.random() * 8 + 1);
} while(numberSeven == numberSix || numberSeven == numberFive || numberSeven == numberFour ||
numberSeven == numberThree ||numberSeven == numberTwo ||numberSeven == numberOne);
do {
numberEight = (int)(Math.random() * 8 + 1);
} while(numberEight == numberSeven || numberEight == numberSix || numberEight == numberFive ||
numberEight == numberFour ||numberEight == numberThree ||numberEight == numberTwo ||
numberEight == numberOne);
do {
numberNine = (int)(Math.random() * 8 + 1);
} while(numberNine == numberEight || numberNine == numberSeven || numberNine == numberSix ||
numberNine == numberFive || numberNine == numberFour ||numberNine == numberThree ||
numberNine == numberTwo || numberNine == numberOne);
array[0][0] = numberOne;
array[0][1] = numberTwo;
array[0][2] = numberThree;
array[1][0] = numberFour;
array[1][1] = numberFive;
array[1][2] = numberSix;
array[2][0] = numberSeven;
array[2][1] = numberEight;
array[2][2] = numberNine;
return array;
}
public static boolean isMagicSquare(int[][] array) {
if(sumRows(int[][] array) == sumColumns(int[][] array) && sumColumns(int[][] array) == sumDiagonals(int[][] array)) {
return true;
}
else {
return false;
}
}
}
dupではなく、Eclipseのバグのようです。 –
Jay、Eclipseの最新バージョンを使用していることを確認してください。 –