Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 11, Problem 3PP

The Fibonacci sequence occurs frequently in nature as the growth rate for certain idealized animal populations. The sequence begins with 0 and 1, and each successive Fibonacci number is the sum of the two previous Fibonacci numbers. Hence, the first ten Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34. The third number in the series is 0 + 1, which is 1; the fourth number is 1 + 1, which is 2; the fifth number is 1 + 2, which is 3; and so on.

 Besides describing population growth, the sequence can be used to define the form of a spiral. In addition, the ratios of successive Fibonacci numbers in the sequence approach a constant, approximately 1.618, called the “golden mean”. Humans find this ratio so aesthetically pleasing that it is often used to select the length and width rations of rooms and postcards.

 Use a recursive formula to define a static method to compute the nth Fibonacci number, given n as an argument. Your method should not use a loop to compute all the Fibonacci numbers up to the desired one, but should be a simple recursive method. Place this static recursive method in a program that demonstrates how the ratio of Fibonacci numbers converges. Your program will ask the user to specify how many Fibonacci numbers it should calculate. It will then display the Fibonacci numbers, one per line. After the first two lines, it will also display the ratio of the current and previous Fibonacci numbers on each line. (The initial ratios do not make sense.) The output should look something like the following if the user enters 5:

Fibonacci #1 = 0

Fibonacci #2 = 1

Fibonacci #3 = 1; 1/1 = 1

Fibonacci #4 = 2; 2/1 = 2

Fibonacci #5 = 3; 3/2 = 1.5

Blurred answer
Students have asked these similar questions
The Fibonacci sequence is listed below: The first and second numbers both start at 1. After that, each number in the series is the sum of the two preceding numbers. Here is an example: 1, 1, 2, 3, 5, 8, 13, 21, ... If F(n) is the nth value in the sequence, then this definition can be expressed as F(1) = 1 F(2) = 1 F(3) = 2 F(4) = 3 F(5) = 5 F(6) = 8 F(7) = 13 F(8) = 21 F(n) = F(n - 1) + F(n - 2) for n > 2 Example: Given n with a value of 4F(4) = F(4-1) + F(4-2)F(4) = F(3) + F(2)F(4) = 2 + 1F(4) = 3 The value of F at position n is defined using the value of F at two smaller positions. Using the definition of the Fibonacci sequence, determine the value of F(10) by using the formula and the sequence. Show the terms in the Fibonacci sequence and show your work for the formula.
A decreasing sequence of numbers is a sequence of integers where every integer in the sequence is smaller than all other previous integers in that sequence. For example, •35, 16, 7, 2, 0, -3, -9 is a decreasing sequence of numbers. The length of this sequence is 7 (total numbers in the sequence) and the difference of this sequence is 35 - (-9) -44. • 5 is a decreasing sequence of numbers with length 1 and difference 5-5 = 0 •99,-99 is a decreasing sequence of numbers with length 2 and difference 99-(-99) = 198 •17, 23, 11, 8, -5, -3 is not a decreasing sequence of %3D numbers. Write a program that contains a main() function. The main function repeatedly asks the user to enter an integer if the previously entered integers form a decreasing sequence of numbers. This process stops as soon as the latest user input breaks the decreasing sequence. Then your function should print the length and difference of the decreasing sequence. Finally, call the main() function such that the call will be…
In mathematics, a prime number is a natural number greater than 1 that is not a product of two smaller natural numbers, i.e. is it has only two factors 1 and itself. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 x 1, involve 5 itself. Note that the prime number series is: 2, 3, 4, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, .. a. Write a Java method named isPrime that takes a natural number as a parameter and returns the if the given number is prime or not using the following header: Public static boolean isPrime (int num) b. Write a Java class called PrimeNumbers that: Reads from the user a natural value n (should be less than or equal 200). Prints a list of the prime numbers from 2 to n and their number and values. The program has to work EXACTLY as given in the following sample run. Hints: You should create a single dimension array to store the prime…

Chapter 11 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Ch. 11.2 - What Java statement will sort the following array,...Ch. 11.2 - How would you change the class MergeSort so that...Ch. 11.2 - How would you change the class MergeSort so that...Ch. 11.2 - If a value in an array of base type int occurs...Ch. 11.3 - Convert the following event handler to use the...Ch. 11 - What output will be produced by the following...Ch. 11 - What output will be produced by the following...Ch. 11 - Write a recursive method that will compute the...Ch. 11 - Write a recursive method that will compute the sum...Ch. 11 - Complete a recursive definition of the following...Ch. 11 - Write a recursive method that will compute the sum...Ch. 11 - Write a recursive method that will find and return...Ch. 11 - Prob. 8ECh. 11 - Write a recursive method that will compute...Ch. 11 - Suppose we want to compute the amount of money in...Ch. 11 - Prob. 11ECh. 11 - Write a recursive method that will count the...Ch. 11 - Write a recursive method that will remove all the...Ch. 11 - Write a recursive method that will duplicate each...Ch. 11 - Write a recursive method that will reverse the...Ch. 11 - Write a static recursive method that returns the...Ch. 11 - Write a static recursive method that returns the...Ch. 11 - One of the most common examples of recursion is an...Ch. 11 - A common example of a recursive formula is one to...Ch. 11 - A palindrome is a string that reads the same...Ch. 11 - A geometric progression is defined as the product...Ch. 11 - The Fibonacci sequence occurs frequently in nature...Ch. 11 - Prob. 4PPCh. 11 - Once upon a time in a kingdom far away, the king...Ch. 11 - There are n people in a room, where n is an...Ch. 11 - Prob. 7PPCh. 11 - Prob. 10PPCh. 11 - Prob. 12PP
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY