I'm writing a 'Sudoku' program, and I need to write a method to check whether a number, the user wants to insert in a certain cell is already contained by the row, column or region. My code looks like this(I'm only checking the row for the number at this point, setNumber returns a boolean value indicating whether the number can be inserted or not):
public boolean setNumber(int row, int column, int number) {
if (this.isEmpty(row, column)) {
if (!this.rowContains(row, number)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
private boolean rowContains(int row, int number) {
for (int i=0; i < this.cells[row].length; i++) {
if (this.cells[row][i].getNumber() == number) {
return true;
}
}
return false;
}
Now, the same number can be inserted multiple times, so apparently rowContains always returns false, but why?