Insectoid @ Sun Nov 01, 2015 12:46 pm wrote:
A stack overflow happens when your program recurses too many times in a row. In this case, it's probably because rows never reaches 0 or 1, so it's recursing infinitely. Does line 13 ever resolve rows to 0 or 1?
That's what I tried to do with lines 3 - 10, but I didn't do it properly. I made it work though.
Java: |
public int triangle(int rows)
{
if(rows == 0)
{
return 0;
}
return rows + triangle(rows - 1);
}
|