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 many days in advance do travelers purchase their airline tickets? Below are data showing the advance days for a sample of 28 passengers on United Airlines Flight 815 from Chicago to Los Angeles....
-
FRAUD PREVENTION AND DETERRENCE IN ACTION Assume the following facts: thirty-day collection period. The invoice is used to post-sales to the accounting system. Checks are received in the mailroom and...
-
Pixel Studio, Inc., is a small company that creates computer-generated animations for films and television. Much of the companys work consists of short commercials for television, but the company...
-
A government institutes a rule that schools are allowed to sell whatever foods it chooses, provided that those foods are not high in sugar. Such a ruling is aligned with which economic system?
-
IBS is a global provider of point-of-sale systems and related services that enable businesses to accept electronic payments. As a new hire in the companys international headquarters accounting...
-
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....
-
Refer to the background information in Exercise 17-60 for the Destin Company. One of the quality improvements management instituted recently was the use of statistical control charts. Over the most...
-
Day Inc. has 4,089 shares of 5%, $100 par value cumulative preferred stock and 94,145 shares of $1 par value common stock outstanding at December 31. What is the annual dividend on the preferred...
-
Briefly Explain Accounting nd taxation with examples and CGT and also Stocks? What is the CGT?
-
Mini Ltd leased a machine from Levi Ltd. The lease is for an item of machinery that, at the inception of the lease, has a fair value of $1,298,674. There is a bargain purchase option that Mini Ltd...
-
Mr. X transferred a track of land under sec 85 to Corp X. ACB of the land 100,000 and the FMV of the land is $3,000,000. In return, Mr. X received cash of 2,000,000 and common shares with a PUC and...
-
Assume the market price of a 14-year bond for Margaret Inc. is $1,075, and it has a par value of $1,000. The bond has an annual interest rate of 7% that is paid semiannually. What is the yield to...
-
Christy has a grandfather clock with a pendulum that is 1.000 m long? (a) If the pendulum is modeled as a simple pendulum, what would be the period? (b) Christy observes the actual period of the...
-
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...
-
Discuss ways in which you could apply the lessons learned in Chapter 13 to improve your ability to read people. Provide specific examples to support your response.
-
Rogers Corp. acquires and places in service a 7 - year class asset on May 9 , 2 0 2 3 , ?for $ 2 5 4 , 3 1 7 ( the only asset placed in service during the year ) . Rogers Corp. does not elect to...
-
Vaughn Corporation purchased equipment for $735000 in 2025. Two years later, the equipment, has accumulated depreciation of $221000 and Vaughn has concerns that the equipment has been impaired....
Study smarter with the SolutionInn App