Question: In Java Calculating Fibonacci numbers with an ArrayList Read this if you want a hint of how to efficiently calculate the Fibonacci numbers. The terms

In Java

In Java Calculating Fibonacci numbers with an ArrayList Read this if youwant a hint of how to efficiently calculate the Fibonacci numbers. The

Calculating Fibonacci numbers with an ArrayList Read this if you want a hint of how to efficiently calculate the Fibonacci numbers. The terms in the Fibonacci sequence are generated by adding the previous two numbers in the sequence. If we start with 1 and 2, the sequence would look like '1, 2, 3, 5, 8, 13, 21, 34, 55, ...' We can efficiently calculate this with an ArrayList by doing the following: - Create an ArrayList of Integers, and add the values 1 and 2 - Repeatedly add the sum of the last two values in the ArrayList (what might the indices of those values be?), and add the result to your ArrayList. Continue this until you would add a value above your threshold. Write a program that does the following: - Asks the user for an Integer threshold (no need to do bounds checking; you can assume the input will be positive) - Calculates and stores all of the Fibonacci numbers less than the threshold in an ArrayList (see under the sample I/O if you want a hint) - Calculates and prints the sum of all the EVEN Fibonacci numbers in your ArrayList Sample I/O Note: people have had problems with output that does not include a newline. We're not grading on prettiness, so just always use system. out.println . Run 1: Enter threshold 90 Sum of even fibonacci numbers is 44 Run 2: Enter threshold 1000 Sum of even fibonacci numbers

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!