Trace the program in Fig. 8.10 for (n=5) and draw the tree similar to the one in
Question:
Trace the program in Fig. 8.10 for \(n=5\) and draw the tree similar to the one in Fig. 8.21 .
Transcribed Image Text:
import java.util..; class Ch8Sample2 { public static void main(String[] args) { Scanner scanner;) scanner = new Scanner (System.in); int n, answer; System.out.println(); System.out.print ("Enter an integer for n: "); n = scanner.nextInt (); System.out.println(); } if (n >= 0) { answer fib(n); System.out.println("The answer is " + answer); } else System.out.println ("Fibonacci not calculated"); System.out.println(); } public static int fib(int n) { int answerl, answer2, answer; if (n > 1) { answerl= fib(n-1); answer2 fib (n-2); answer = answerl + answer2; } else answer n; return answer; // Line 1 // Line 2 // Line 3 // Line 4 // Line 5 // Line 6 // Line 7 // Line 8 // Line 9 // Line 10 // Line 11 // Line 12 // Line 13 // Line 14 // Line 15 // Line 16 // Line 17 // Line 18 // Line 19 // Line 20 // Line 21 // Line 22 // Line 23 // Line 24 // Line 25 // Line 26 // Line 27 // Line 28 // Line 29 // Line 30
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (1 review)
The provided program in Java is a recursive method to calculate Fibonacci numbers A Fibonacci sequen...View the full answer
Answered By
Reuben Komen
0.00
0 Reviews
10+ Question Solved
Related Book For
Guide To Java A Concise Introduction To Programming
ISBN: 978-3031228414
2nd Edition
Authors: James T. Streib, Takako Soma
Question Posted:
Students also viewed these Computer science questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Let r and s be solutions to the quadratic equation x 2 b x + c = 0. For n N, define d0 = 0 d1 = r s dn = b dn1 c dn2 (n 2) Prove that dn = r n s n for all n N. [4 marks] (b) Recall that a commutative...
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
A 35 ft3 rigid tank has air at 225 psia and ambient 600 R connected by a valve to a piston cylinder. The piston of area 1 ft2 requires 40 psia below it to float, Fig. P3.99. The valve is opened and...
-
You heat a gas 10 K at P = C. Which one in table A.5 requires most energy? Why?
-
Would critical ratio be better utilized as a static ratio or a dynamic ratio, and why?
-
If a straight-line probabilistic relationship relates the mean LO9 E(y) to an independent variable x, does it imply that every value of the variable y will always fall exactly on the line of means?...
-
Select any three countries that might have some logical basis for establishing a multinational market organization and illustrate their compatibility as a regional trade group. Identify the various...
-
A zero-coupon bond trades for a price of $96 per $100 par. It matures in 4 years has a 0.00% coupon and compounds semi-annually. What is the yield of this bond?
-
Write a recursive method to reverse a given string. The method accepts a string as a parameter and returns the reverse of the string. For example, if the argument is Java, then the method returns...
-
Trace the program in Fig. 8.1 for \(x=2\) and \(n=5\) and draw the tree similar to the one in Fig. 8.21. import java.util.*; class Ch8Samplel { public static void main(String[] args) { Scanner...
-
The following information is from the accounts of Depree Manufacturing Company for 2018: Required a. Divide the class into groups of four or five students per group and organize the groups into three...
-
Carla Vista Corp. sponsors a defined benefit pension plan for its employees. On January 1, 2025, the following balances relate to this plan Plan assets $489,900 Projected benefit obligation 616,700...
-
Question 2 of 8 Shirts were purchased for $12.50 each and were marked up by $18.75. During Christmas, they were discounted by $6.85 per shirt. a. What was the rate of markdown? % Round to two decimal...
-
The cost versus quality decision is one that only few companies get right. What is the cost of quality? It is very high for some companies such as Ford and Bridgestone/Firestone, whose reputations...
-
Find the absolute maximum and absolute minimum values of the function f(x) (x-2)(x-5)+7 = on each of the indicated intervals. Enter 'NONE' for any absolute extrema that does not exist. (A) Interval =...
-
4. Roll one 10-sided die 12 times. The probability of getting exactly 4 eights in those 12 rolls is given by (a) 10 9 4 10 10 (b) HA 9 -HAA (c) 1 (d) 9 (c) 10 9 () 10
-
In calculating the shape of a gravity-flow discharge chute that will minimize transit time of discharged granular particles, C. Chiarella, W. Charlton, and A.W. Roberts [CCR] solve the following...
-
XYZ Inc. a calendar year, accrual basis corporation, had the following items during 2021: Gross revenue from operations Cost of goods sold $420,000 ($180,000) $9,000 LT capital gain .LT capital...
-
Use a member function to overload the multiplication operator for the Stonewt class; have the operator multiply the data members by a type double value. Note that this will require carryover for the...
-
What are this and *this?
-
Modify the Vector class header and implementation files (Listings 11.13 and 11.14) so that the magnitude and angle are no longer stored as data components. Instead, they should be calculated on...
-
Fig 1. Rolling a 4 on a D4 A four sided die (D4), shaped like a pyramid (or tetrahedron), has 4 flat surfaces opposite four corner points. A number (1, 2, 3, or 4) appears close to the edge of each...
-
I just need help with question #4 please! Thank you! Windsor Manufacturing uses MRP to schedule its production. Below is the Bill of Material (BOM) for Product A. The quantity needed of the part...
-
(25) Suppose that we have an economy consisting of two farmers, Cornelius and Wheaton, who unsurprisingly farm corn c and wheat w, respectively. Assume that both farmers produce their crop of choice...
Study smarter with the SolutionInn App