I have a recursive method that I am fairly certain is finite. However, when I run it I receive a stack overflow error. Is there another possible way to get stack overflow that I happen to be doing or what is wrong with the method?
public static void solve(int row, int column){
if (row<=8){
if (column>8){
solve(row+1, 0);
}
if (row<=8 && column<=8 && (Rows[row][column]==0)){
for (int a = 1; a<=9;a++){
if (check(row, column, a)==false&&Rows[row][column]!=a){
Rows[row][column]=a;
break;
}
}
}
solve(row, column+1);
}
}
if (column>8) solve(row+1, 0); else solve(row, column+1);. The single linesolve(row, column+1);in your code should only be used ifcolumn>8is false.