Question: Change Figure 11.2s recursive Factorial program so that it uses tail recursion. Figure 11.2 1234 4 5 6 7 8 9 10 11 12 13

Change Figure 11.2’s recursive Factorial program so that it uses tail recursion.

Figure 11.2

1234 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 import

1234 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 import java.util.Scanner; public class Factorial { public static void main(String[] args) ( Scanner stdIn = new Scanner(System.in); int num; System.out.print("Enter a non negative number: "); num= stdin.nextInt(); if (num > 0) ( System.out.println(factorial(num)); } } // end main //** private static int factorial (int n) { int nF; // n factorial if (n C == nF - 1; } else { 1 || n - 0) nFn factorial(n-1); } return nF; } // end factorial } // end Factorial class Sample session: Enter a nonnegative number: 5 120 stopping condition recursive method call

Step by Step Solution

3.45 Rating (148 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

In the provided Java code for calculating factorial the recursion is not in the tailrecursive form A ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction To Programming With Java A Problem Solving Approach Questions!