所以我的代码有点问题。假设要交叉检查相同整数的行和列。
这是我到目前为止所拥有的......但是当我运行它时,它似乎只检查第一个整数。(例如数独板的第一行读取。1 2 2 2 2 2 2 2 2 2)它不会检测到明显的倍数 2 但如果我将输入更改为 1 1 2 2 2 2 2 2 2 错误将会出现在这种情况下最多为多个 1。多个任何建议来调整我的循环以使其通过列?
public static void validate(final int[][] sudokuBoard) {
int width = sudokuBoard[0].length;
int depth = sudokuBoard.length;
for (int i = 0; i < width; i++) {
int j = i;
int reference = sudokuBoard[i][j];
while (true) {
if ((j >= width) || (j >= depth)) {
break;
}
else if (i == j){
// do nothing
}
else if (j < width) {
int current = sudokuBoard[i][j];
if (current == reference) {
System.out.print("Invalid entry found (width)" + "\n");
System.out.print(current + "\n");
// invalid entry found do something
}
} else if (j < depth) {
// note reversed indexes
int current = sudokuBoard[j][i];
if (current == reference) {
System.out.print("Invalid entry found (depth)" + "\n");
System.out.print(current + "\n");
// invalid entry found do something
}
}
j++;
}