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...
-
How much evidence is needed to be persuasive? Each of the following scenarios describes the auditor's findings of internal control. Required For each situation, indicate whether additional evidence...
-
Conrad Corporation has a budget to produce 2,000 units at a variable cost of \($3\) per unit, but actual production is 1,800 units with an actual cost of \($3.20\) per unit. What is the flexible...
-
Pittsburgh Aluminum Company uses a process cost system to record the costs of manufacturing rolled aluminum, which consists of the smelting and rolling processes. Materials are entered from smelting...
-
The boxplot below shows salaries for Construction workers and Teachers. Construction Teacher 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 Salary (thousands of $) Q Jennie makes the median...
-
Think about your school or local library and the processes involved in checking out books, signing up new borrowers, and sending out overdue notices, all from the librarys perspective. Describe three...
-
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....
-
Use the elimination method to solve each system of linear equations, if possible. Identify the system as consistent or inconsistent. 6x - 15y = 12 -4x+10y=-8
-
What are the 3 proximate causes of economic growth? words. Explain the capital accumulation equation K++1 = Kt + It dKt in your own -
-
State capitalism has become popular in emerging markets other than China, such as Russia, India, and Brazil. What is the primary objective of state capitalism? Explain.
-
1. Briefly explain what an unemployment rate is and what part of a country's population is used to calculate it. How can the unemployment rate be used as an indicator of economic health? (4 points)...
-
Over the past few years, avocados - a tropical fruit originating in Mexico - have become very popular in the U.S., which is the largest avocado consuming country, and across the world. Avocados have...
-
Compare Income Statements and Balance Sheets of Competitors a. Following are selected income statements from two pharmaceutical companies, Pfizer and Dr. Reddy's, for their respective 2018 fiscal...
-
To test H0: = 5.2 versus H1: 5.2, a simple random sample of size n = 18 is obtained from a population that is known to be normally distributed. (a) If the sample standard deviation is determined...
-
Use multiplication or division of power series to find the first three nonzero terms in the Maclaurin series for each function. y = e x2 cos x
-
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...
-
Majestic Corporation began the year with accounts receivable, inventory, and prepaid expenses totaling $63,000. At the end of the year, Majestic had a total of $77,000 for these current assets. At...
-
Goshford Company produces a single product and has capacity to produce 155,000 units per month. Costs to produce its current sales of 124,000 units follow. The regular selling price of the product is...
-
The Town of Weston has a Water Utility Fund with the following trial balance as of July 1, 2019, the first day of the fiscal year: Cash Customer accounts receivable Allowance for uncollectible...
Study smarter with the SolutionInn App