0

Why am I getting a stack overflow exception? Isn't this meant to be a 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

  at test3.Test.tailFact(Test.java:13)
  at test3.Test.tailFact(Test.java:13)
  ...
*/
2

1 Answer 1

4

Java doesn't support tail recursion.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.