A recursive method is one that calls itself. Your recursive methods will not need a loop. A non-recursive method doesn't call itself, and in this
A recursive method is one that calls itself. Your recursive methods will not need a loop.
A non-recursive method doesn't call itself, and in this assignment your non-recursive methods will need a loop.
For factorial, whether recursive or not, the smallest possible value of n should be zero , and 0! (factorial zero) = 1.
Fibonacci(n) is the nth Fibonacci number. The Fibonacci sequence is this:
1, 1, 2, 3, 5, 8, 13,..... Fibonacci(0) and Fibonacci(1) are both 1. Fibonacci(2) is 2, Fibonacci(4) is 5 etc.
HERE IS THE SHELL
package h10;
public class H10 {
public static void main(String[] args) { System.out.println("Non recursive Factorial"); for (int i=0; i<=10; i++) System.out.println("Factorial " + i + " equals " + factorial(i)); System.out.println(); System.out.println("Recursive Factorial"); for (int i=0; i<=10; i++) System.out.println("Factorial " + i + " equals " + recFactorial(i)); System.out.println(); System.out.println("Non recursive Fibonacci"); for (int i=0; i<=10; i++) System.out.println("The " + i + "th Fibonacci number is " + fibonacci(i)); System.out.println(); System.out.println("Recursive Fibonacci"); for (int i=0; i<=10; i++) System.out.println("The " + i + "th Fibonacci number is " + recFibonacci(i)); }//main }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started