Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Im a writing a sudoku solver in JAVA. The functions check whether the given valu

ID: 3780813 • Letter: I

Question

Im a writing a sudoku solver in JAVA.

The functions check whether the given value "val" fits in the cell by looking at the row, column and box.

The functions are used here:

121 checks if val is an acceptable value for the row i 122 private boolean checkRow(int val, int i) t TODO 123 124 125 126 checks if val is an acceptable value for the column j 127 private boolean checkcol(int val, int j) t TODO 128 130 131e checks if val is an acceptable value for the box around 132 the cell at row i and column j 133 134e private boolean checkBox (int val, int i, int j) t TODO 135 136

Explanation / Answer

/** checks if val is an acceptable value for the given row i*/
private boolean checkRow( int val, int i )
{
for( int c = 0; c < 9; c++ )
if( sudoku[i][c] == val )
return false ;

return true;
}

/** checks if val is an acceptable value for the given column j*/
private boolean checkCol( int val, int j )
{
for( int r = 0; r < 9; r++ )
if( sudoku[r][j] == val )
return false ;

return true ;
}

/** checks if val is an acceptable value for the box around row i and column j */
private boolean checkBox( int i, int j, int val )
{
i = (i / 3) * 3 ;
j = (j / 3) * 3 ;

for( int r = 0; r < 3; r++ )
for( int c = 0; c < 3; c++ )
if( sudoku[i+r][j+c] == val )
return false ;

return true ;
}