Class Sudokumatrix {
Private int[][] Matrix = new Int[][] {
{0, 5, 0, 6, 0, 1, 0, 0, 0},
{0, 0, 7, 0, 9, 0, 0, 2, 0},
{3, 0, 0, 0, 0, 4, 0, 0, 1},
{9, 0, 0, 0, 0, 0, 1, 3, 0},
{0, 0, 8, 0, 5, 0, 7, 0, 0},
{0, 2, 6, 0, 0, 0, 0, 0, 8},
{7, 0, 0, 9, 0, 0, 0, 0, 5},
{0, 9, 0, 0, 4, 0, 3, 0, 0},
{0, 0, 0, 2, 0, 8, 0, 1, 0},
};
public void Run () {
Calc ();
}
private void Calc () {
int[] coordinate = Getnextdata ();
int m = coordinate[0];
int n = coordinate[1];
for (int k = 1; k <= 9; k++) {
if (CheckNumber (m,n,k)) {
Matrix[m][n] = k;
SYSTEM.OUT.PRINTLN (M + "," + N + "with" + K);
if (getnextdata () = = null) {
print (matrix);
}
else {
Calc ();
}
}
}
Matrix[m][n] = 0;
}
Private int[] Getnextdata () {
for (int row = 0; row < 9; row++) {
for (int col = 0; col < 9; col++) {
if (matrix[row][col] = = 0) {
Int[] Coordinateofemptysquare = {row, col};
return coordinateofemptysquare;
}
}
}
return null;
}
Private Boolean checknumber (int row, int col, int n) {
for (int i = 0; i < 9; i++) {
if (matrix[row][i] = = N | | matrix[i][col] = = N) {
return false;
}
}
Int[] Lefttop = {row-(row% 3), col-(col% 3)};
for (int r = lefttop[0]; r <= Lefttop[0] + 2; r++) {
for (int c = lefttop[1]; c <= Lefttop[1] + 2; C + +) {
if (matrix[r][c] = = N) {
return false;
}
}
}
return true;
}
public void print (int[][] grid) {
for (int i = 0; i < 9; i++) {
for (int j = 0; J < 9; J + +) {
System.out.print (Grid[i][j] + "");
}
System.out.println ();
}
System.out.println ();
}
}
Sudoku small algorithm, test pass (Java)