java - Stack overflow with tail recursion -
why getting stack overflow exception? isn't meant tail recursive function?
public static int tailfact(int n, int mult) { if(n == 0) { return mult; }else { return tailfact(n-1, n*mult); } } public static int factt(int n) { return tailfact(n, 1); } public static void main(string[] args) { factt(100000); } /*exception in thread "main" java.lang.stackoverflowerror @ test3.test.tailfact(test.java:13) @ test3.test.tailfact(test.java:13) ... */
java doesn't support tail recursion.
Comments
Post a Comment