Question: Java Programming Tasks: Part I: Recursion 1. If you know that, in mathematics, the Fibonacci numbers, commonly denoted Fn, form a sequence, called the Fibonacci


Tasks: Part I: Recursion 1. If you know that, in mathematics, the Fibonacci numbers, commonly denoted Fn, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, Fo=0, F =1, and, Fn = Fn-1 + Fn-2 The beginning of the sequence is thus: 0,1, 1, 2, 3, 5, 8, 13, 21, ... a. Write a recursive function (method) to find the nth number in Fibonacci sequence. b. Write an iterative function (method) to find the nth number in Fibonacci sequence. c. Report the time elapsed by both functions in milliseconds*. The time elapsed by a function is the difference of the time reported after calling the function to the time reported before calling the function. long start = System.currentTimeMillis(); // your function call long finish = System.currentTimeMillis(); long time Elapsed = finish - start; System.out.println(timeElapsed + " ms"); Problems Javadoc Declaration Console cterminated FibonacciTest Java Application C:\Program Files\Javaljre 18.0 231\biniljavaw.exe (Feb 10, 2020, 10:50:46 PM) Fibonacci #40 using recursion function: 102334155 256 ms Fibonacci #40 using Iterative function: 102334155 Oms *To see the significant difference, try big numbers such as: 40. Part II: Lambda Expressions 2. Suppose that a functional interface Array Processor is defined as public interface ArrayProcessor { double apply( double[] array ); In the main method of a class that you create later, we defined a function that returns the length of an array of type double and used it as: double[] firstList = { 6, 2.6, 3, 5, 7, 12, 7, 2.5, 10.3, 1.7 }; ArrayProcessor numberOfElements = (array) -> { return array.length;}; System.out.println(numberOfElements.apply(firstList)); //prints 10 Now, using the same concept, lambda, you write and use the following functions: a. A function to find the maximum value in an array. b. A function to find the minimum value in an array. C. A function to find the sum of the values in an array. d. A function to find the average of the values in an array. Both your programs should have program description header that goes at the top of the file which gives information about the programmer and program. // Name: Bob Programmer // Section: A, B, or s // Program Name: Hello World // // Description: A brief description of the program. What does the Il program do (not how it does it: for example, it uses loops)? Does // the program get input? What kind? What information is output // from the program and to where (screen or file) //// import
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
