recursion - Error Within Code


this set of code producing stack overflow error due infinite recursion (at least, think is). have been staring @ code long time , can't figure out error happens be. if can point out why getting such error, great.

public void drawvalues(graphics g, graphics2d g2, int x, int y, int a, int b){         if (b>8){             b = 0;             a++;             x = 61;             y+=66;         }         if (a==8 && b==8){             g.drawstring(string.valueof(solver.rows[a][b]), x, y);         }         else{             g.drawstring(string.valueof(solver.rows[a][b]), x, y);             drawvalues(g,g2, x+66, y, a, b++);         }     } 

it state rows 9x9 2d array, , b start @ 0

this because using post-increment(b++) instead of pre-increment(++b) when make recursive calling of drawvalues method. if use post-increment, argument increment after method has been invoked. hence, in case, variable b never changed.

so, should use pre-increment:

... drawvalues(g,g2, x+66, y, a, ++b); ... 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -