简体   繁体   中英

Is Stack OverFlow Error possible in finite recursion?

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);
    }
}

Stack size in JVM is limited so it is possible to get StackOverflow with finite recursion or even without any recursion.

You can increase JVM stack size using -Xss option:

java -Xss16M YouMainClass

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM