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. (Hint: Use a static variable and increment it every time the method is called.)
Data from Listing 18.2,
Transcribed Image Text:
1 1mport java.util.Scanner; 2 3 publ1c class ComputeFibonacci { 1** Main method / publ1c static vo1d main(String[] args) { /I Create a Scanner Scanner input = new Scanner (System.in): System.out.print("Enter an 1ndex for a F1bonacc1 number: "): int index = input.nextInt (): 4 5 6 7 8 9 10 II Find and display the Fibonacci number Sy stem.out.printin("The F1bonacc1 number at index " + index + " 1s " + fib(index)): 11 12 13 14 15 1* The method for finding the Fibonacci number / publ1c static long fib(long index) { 1f (index == 0) IT Base case return 0; else 1f (index == 1) / Base case return 1; else 16 17 18 19 20 21 II Reduction and recursive calls return fib(index - 1) + fib(index - 22 23 24 25 }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (12 reviews)
import javautilScanner public class Exercise1807 static int count 0 public static void mainString ar...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 And Data Structures Comprehensive Version
ISBN: 9780136520238
12th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Modify Listing 18.8, TowerOfHanoi.java, so the program finds the number of moves needed to move n disks from tower A to tower B. (Hint: Use a static variable and increment it every time the method is...
-
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...
-
//Question3.cpp // This program finds the average time spent programming by a student // each day over a three day period. #include using namespace std; int main() { int n; int numStudents; float...
-
Determine the vector A-C, given the vectors A and C in the figure. (Figure 1) Figure B (B=26.5) 56.0% (A = 44.0) 28.0 C(C= 31.0) 1 of 1 Determine the magnitude of the vector A - . Express your...
-
A student has 23 candy sticks in a bag, with lengths that are normally distributed. Each stick is, on average 1.8 cm long, with standard deviation 0.5 cm. What is the probability that the total...
-
Background You are an audit manager at Oscar Edwards Vance (OEV), an accounting firm with offices throughout regional Australia in major centres such as Bathurst, Goulburn, Coffs Harbour and Armidale...
-
4. What effect does the elimination of intercompany sales and cost of goods sold have on consolidated net income?
-
You have the following information for Goodspeed Diamonds. Goodspeed Diamonds uses the periodic method of accounting for its inventory transactions. Goodspeed only carries one brand and size of...
-
I need the answer as soon as possible The company's contribution format income statement for 2020 is given below: $ Sales (20,000 phones) Variable expenses 1,200,000 900,000 300,000 Contribution...
-
1. Here are the densities and redii of planets in our solar system (in grams per cm 3 and km, respectively) How much would you weigh on these different planets? 1 pound is equal to 0.453592 kg. 2....
-
Using the BigInteger class introduced in Section 10.9, you can find the factorial for a large number (e.g., 100!). Implement the factorial method using recursion. Write a program that prompts the...
-
Write a recursive method that computes the sum of the digits in an integer. Use the following method header: public static int sumDigits(long n) For example, sumDigits(234) returns 2 + 3 + 4 = 9....
-
Sea Biz Co. has four employees. FICA Social Security taxes are 6.2% of the first $106,800 paid to each employee, and FICA Medicare taxes are 1.45% of gross pay. Also, its FUTA taxes are 0.8% and SUTA...
-
Home Base, Incorporated reports the following production cost information: Units produced 97,000 units Units sold 92,000 units Ending finished goods inventory 5,000 units Direct labor $17 per unit...
-
About New York City public sector finance. The other way is to delineate the problem. We should use data to show a problem, and then analyze the environment in which budgeting takes place to suggest,...
-
From a survey a company has determined that 23% of its customers are classified as "advocates" , 68% as "passives" and the remainder as "detractors" . Research suggests that during a year 15% of the...
-
The following are the transactions of Spotlighter, Incorporated, for the month of January. a. Borrowed $3,940 from a local bank on a note due in six months. b. Received $4,630 cash from investors and...
-
1. What are the deeper problems that plague in different forms it takes throughout the world according to the authors? Please, briefly explain. 2. Why was Joseph Schumpeter a pessimist about the...
-
Two products (W and X) are created from a joint process. Both products can be sold immediately after split-off.There are no opening inventories or work in progress.The following information is...
-
A liquid flows upward through a valve situated in a vertical pipe. Calculate the differential pressure (kPa) between points A and B. The mean velocity of the flow is 4.1 m/s. The specific gravity of...
-
Rewrite Programming Exercise 14.10 so that the cylinder?s width and height are automatically resized when the window is resized. Write a program that draws a cylinder, as shown in Figure. You can use...
-
Draw a circle with three random points on the circle. Connect the points to form a triangle. Display the angles in the triangle. Use the mouse to drag a point along the perimeter of the circle. As...
-
Write a program that enables the user to drag the vertices of a triangle and displays the angles dynamically as the triangle shape changes, as shown in Figure 15.30a. The formula to compute angles is...
-
The company sold merchandise to a customer on March 31, 2020, for $100,000. The customer paid with a promissory note that has a term of 18 months and an annual interest rate of 9%. The companys...
-
imer 2 0 2 4 Question 8 , PF 8 - 3 5 A ( similar to ) HW Score: 0 % , 0 of 1 0 0 points lework CH 8 Part 1 of 6 Points: 0 of 1 5 Save The comparative financial statements of Highland Cosmetic Supply...
-
An investor wants to purchase a zero coupon bond from Timberlake Industries today. The bond will mature in exactly 5.00 years with a redemption value of $1,000. The investor wants a 12.00% annual...
Study smarter with the SolutionInn App