So i've update my code and im still stumped on how to check a 3x3 block within a completed sudoku board to see if it doesn't have any repeating numbers. this is my method that i've updated.
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
this is the calling method i don't know which parametrs to send to the method 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");
}
}
访问数组中的单元格应该使用方括号,并且seen
一个数组:
seen[sudokuBoard[referenceColumn+i][referenceRow+j]]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.