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...
-
Production Overhead Cost Budget Linden Nursery grows and sells potted perennial plants, as well as ornamental and fruit trees. The owner of Linden Nursery has determined that variable overhead costs...
-
What is the exemplar approach to categorization? How does it differ from the prototype approach, and how might the two approaches work together? L01
-
Determining Bad Debt Expense Based on Aging Analysis Blue Skies Equipment Company uses the aging approach to estimate bad debt expense at the end of each accounting year. Credit sales occur...
-
Required information (The following information applies to the questions displayed below.] Sierra Company manufactures woven blankets and accounts for product costs using process costing. Data below...
-
The president of Conglomerate Corporation has instructed you, the Controller, to report quarterly profits within 2% of the projected budget and those figures will be reported to all stakeholders ....
-
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
-
Consider the two alcohol molecules shown below: (a) Are they isomers? Justify your answer. (b) Molecule (a) is more soluble in water than molecule (b). Explain why. HO + (a) (9) OH
-
1. How will you check if a class is a child of another class? 2. What is init method in python?
-
1. What are lists and tuples? What is the key difference between the two? 2. What is Scope in Python?
-
1. What is an Interpreted language? 2. What is a dynamically typed language?
-
Q.1 If denotes increasing order of intensity, then the meaning of the words [talk shout scream] is analogous to [please pander]. Which one of the given options is appropriate to fill the blank? (A)...
-
Refer to Exercises 5 and 7. a. Find the critical value for a 99% confidence interval for the slope of the true regression line. Then calculate the confidence interval. b. Interpret the interval from...
-
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.
-
Calculate the present value of cash flows, 1500 in the years 1, 2, 3, and 4, then grows at 2% every year, using 10% discount rate. Round and write up to two decimals (e.g., 100.00). No characters...
-
What are the two formats that companies can use to present their Statement of Comprehensive Income?
-
Problem 15-19 (Algo) Initial direct costs; sales-type lease (LO15-2, 15-7) Bidwell Leasing purchased a single-engine plane for its fair value of $834,564 and leased it to Red Baron Flying Club on...
Study smarter with the SolutionInn App