Is not tail rec (can go on stackoverflow) and moreover Java does not support tail rec optimization. If you really want to go with rec mode you should use an accumulator.
Yep. The code will indeed go into an infinite recursion if n is less than 1 (negative number or 0), resulting in a stack overflow error.
Doesn't this go into an infinite loop if I put in ) or any negative number? if n == 0 then we call 0 + triangular(-1) and so on and so forth.
Thanks!
It should have "arrays" instead of "strings" on its tags.
Doesn't work for negative input!
Loading collection data...
Is not tail rec (can go on stackoverflow) and moreover Java does not support tail rec optimization.
If you really want to go with rec mode you should use an accumulator.
Yep. The code will indeed go into an infinite recursion if n is less than 1 (negative number or 0), resulting in a stack overflow error.
Doesn't this go into an infinite loop if I put in ) or any negative number?
if n == 0 then we call 0 + triangular(-1) and so on and so forth.
Thanks!
It should have "arrays" instead of "strings" on its tags.
Doesn't work for negative input!