Question: Please write in java! Do each method as its own program, dont join the two together. Use timer provided in picture for each different program...
Lab # 2 Fibonacci Sequence Write a recursive and an iterative function to calculate the nth element in a Fibonacci sequence. A Fibonacci sequence is defined as the element 1, followed by another 1, and each element thereafter is the sum of the previous two elements. For example, the first 9 elements of a Fibonacci sequence are: 12358 13 21 34 This famous sequence was originally used to predict the growth of rabbit populations Once you have each of the functions working for n qual to 40, determine which method is more efficient by timing the two separate function calls and printing out the time required for each method call to return the 40th element in the sequence. Return the 40th element to main and print it. After that, print out a complete Fibonacci sequence from element 1 to element 40, along with its position number 2. 1 3. 2 4. 3 This last part should not be timed. The timer function you need for this Project is: new Date(); long milliseconds # D1.getTime(); OR Date d1 long start System.currentTimeMillis()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
