Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions