Modify Listing 18.2, ComputeFibonacci.java, so that the program finds the number of times the fib method is
Question:
Modify Listing 18.2, ComputeFibonacci.java, so that the program finds the number of times the fib method is called.
Listing
Transcribed Image Text:
1 import java.util.Scanner; 2 3 public class ComputeFibonacci { 4 /** Main method */ public static void main(String] args) { // Create a Scanner Scanner input = new Scanner(System.in); System.out.print("Enter an index for a Fibonacci number: "); int index - input.nextInt(); 10 11 12 13 14 15 16 17 18 19 // Find and display the Fibonacci number System.out.println("The Fibonacci number at index " + index + " is " + fib(index)); /** The method for finding the Fibonacci number */ public static long fib(long index) { if (index == 0) // Base case return 0; 20 else if (index == 1) // Base case return 1; else // Reduction and recursive calls return fib(index - 1) + fib(index - 2); 21 22 23 24 25 } Enter an index for a Fibonacci number: 1 pteter The Fibonacci number at index 1 is 1 Enter an index for a Fibonacci number: 6 Jerter The Fibonacci number at index 6 is 8 Enter an index for a Fi bonacci number: 7 -Erter The Fibonacci number at index 7 is 13
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (12 reviews)
Output Enter an index for the Fibonacci number 7 Fibonacci number at index 7 is 13 The number of tim...View the full answer
Answered By
Utsab mitra
I have the expertise to deliver these subjects to college and higher-level students. The services would involve only solving assignments, homework help, and others.
I have experience in delivering these subjects for the last 6 years on a freelancing basis in different companies around the globe. I am CMA certified and CGMA UK. I have professional experience of 18 years in the industry involved in the manufacturing company and IT implementation experience of over 12 years.
I have delivered this help to students effortlessly, which is essential to give the students a good grade in their studies.
3.50+
2+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Modify Listing 18.8, TowerOfHanoi.java, so that the program finds the number of moves needed to move n disks from tower A to tower B. Listing 1 import java.util.Scanner; 2 3 public class Tower0fHanoi...
-
Modify Listing 12.18 WebCrawler.java to search for the wordComputer Programming starting from the URL http://cs.armstrong.edu/liang . ?Your program terminates once the word is found. Display the URL...
-
Modify Listing 14.21, ClockPane.java, to add the animation into this class and add two methods start() and stop() to start and stop the clock. Write a program that lets the user control the clock...
-
Dalmo Bhd is an investment holding company and currently it has 3 subsidiaries as stated below. Dalmo Bhd group of companies financial year end is 31st March. The shareholding structure of Dalmo...
-
Let be a convex preference relation on a linear space X. The set of best elements X* ={x : x y for every y X} is convex. A slightly stronger notion of convexity is often convenient (example...
-
In Problems 4150, graph each inequality subject to the nonnegative restrictions. 16x - 12y4,800, x = 0, y 0
-
Does Fairmont have any contactor personnel whose have terminated but are being paid through payroll after termination (e.g., ghost employees)?
-
Solutions Plus is an industrial chemicals company that produces specialized cleaning fluids and solvents for a wide variety of applications. Solutions Plus just received an invitation to submit a bid...
-
Antelopes, native to Africa and Asia, range in size from 30 cm to over 180 cm at the shoulder, with most between 90-120 cm. This is related to the humerus length. The data below gives the length and...
-
In elementary school (grades 1 to 6), there is a strong association between a childs height and the childs reading ability. Taller children tend to be able to read at a higher level. However, there...
-
Write a recursive method that displays a string reversely on the console using the following header: public static void reverseDisplay(String value) For example, reverseDisplay("abcd") displays dcba....
-
Write a recursive method to compute the following series: Write a test program that displays?m(i)?for?i?=?1,?2, . . .,?10. 2 3 4 6. m(i) 3 ... 2i + 1 5 9. 13 11
-
Refer to the financial statements of Campbell Soup Company in Appendix A. Required: a. By means of T-account analysis, explain the changes in Campbell's Property, Plant, and Equipment account for...
-
ABC Inc. ships its computer products to Buffalo, New York. In 2019, the company shipped 4 million pounds of product through several areas in Buffalo. The logistic Costs in 2019 are given in the table...
-
The Village Stitchery will custom-make any knit or crochet pattern selected for just $0.003 per inch of yarn used to complete said project. Virginia selects a pattern for an over-sized blanket that...
-
Explain globalization of markets? What are the forces that led the process of globalization? What is the prediction of Levitt about the same two decades about the same? Was he right?
-
If a company contributes 4 percent of an employee's salary to the employee's cash balance savings account at the end of the year, and the annual interest rate is 2.5 percent, what is the balance in...
-
During its first year of operations, Fletcher produced 50,000 units and sold 40,000 units. During its second year of operations, it produced 40,000 units and sold 50,000 units. The selling price of...
-
Following the preparation of the bank reconciliation for Lolitta Services, a correcting journal entry was needed. A cheque issued for the correct amount of $960 for a payment on account was recorded...
-
Explain the operation of the dividends received deduction.
-
Assume that we are using a linked representation of a complete binary tree T, and an extra reference to the last node of that tree. Show how to update the reference to the last node after operations...
-
Show how to implement the FIFO queue ADT using only a priority queue and one additional integer instance variable.
-
Show how to implement the stack ADT using only a priority queue and one additional integer instance variable.
-
Write summary of 300 words, with references and 2 question regarding the Feminist Work and Community Education Viv Rogers The concept of community education is subject to similar confusions of...
-
Explain scanning the internal and external environment of the organization.
-
ANSWER ALL QUESTIONS 1. Illustrate and explain with examples the risk-return trade off graph of money market, foreign exchange market, bond market, equity market and derivatives market. State and...
Study smarter with the SolutionInn App