/* * DON'T FORGET TO PUT YOUR IDENT BOX HERE */ public class factorial { /** * Calculates a given term in the Fibonocci sequence using recursion. * The sequence is defined as follows: * fib(1) = 1 * fib(2) = 1 * fib(n) = fib (n-1) + fib(n-2) for n >2. * @param term the term to calculate. * @return the appropriate term in the Fibonocci sequence. */ public static int fib(int term) { if (term <= 2) { return 1; } else { return (fib(term - 1) + fib(term - 2)); } }//end int fib(int term) /** * Calculates the factorial of a number using recursion. * @param n the number to find the factorial of. * @return the factorial of the number. */ public static int fact(int n) { /* You need to replace the following line with your code to compute the factorial of a number (hint: look at what we did in the fib function )*/ return 0; }// end int fact(int n) /** * A debugging main. */ public static void main(String argv[]) { /* The following will run the required tests for you and print the results to the * display. */ System.out.println("Testing fib(1): \n Expected: 1 \n Program Returned: " + fib(1)); System.out.println("Testing fib(2): \n Expected: 1 \n Program Returned: " + fib(2)); System.out.println("Testing fib(6): \n Expected: 8 \n Program Returned: " + fib(6)); System.out.println("\n ----------------------------- \n"); System.out.println("Testing fact(0): \n Expected: 1 \n Program Returned: " + fact(0)); System.out.println("Testing fact(3): \n Expected: 6 \n Program Returned: " + fact(3)); System.out.println("Testing fact(9): \n Expected: 362880 \n Program Returned: " + fact(9)); }// end debugging main } //end class factorial