所以我更新了我的代码,但我仍然不知道如何检查一个完整的数独板中的 3x3 块,看看它是否没有任何重复的数字。这是我更新的方法。
static boolean isBlock1Valid(int[][] sudokuBoard, int referenceRow, int referenceColumn)
{
boolean[] seen = new boolean[9];
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
if ( seen(sudokuBoard[referenceColumn+i][referenceRow+j])) return false;
else ( seen(sudokuBoard[referenceColumn+i][referenceRow+j])) = true;
}
}
return true;
}//end of isBlock1Valid
这是调用方法,我不知道要向方法 isBlock1Valid 发送哪些参数
public static void Validate(final int[][] sudokuBoard)
{
int width = sudokuBoard[0].length;
int height = sudokuBoard.length;
for(int i = 0; i < width; i++)
if(!IsValidRow(sudokuBoard, i, width))
{
System.out.print("Invalid entry found \n (Row)" + "\t"+ i + "\n");
//Do something - The row has repetitions
}
else{
System.out.print("Row " +i + " is valid \n");
}
for(int j = 0; j < height; j++)
if(!IsValidColumn(sudokuBoard, j, height))
{
System.out.print("(Column)" + j + "\n");
//Do something - The columns has repetitions
}
else{
System.out.print("Column " +j +" is valid \n");
}
for(int i=0; i<2; i++)
if(!IsBlock1Valid(sudokuBoard,i, j)){
System.out.print("hi");
}
}