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
Step by Step Answer:
This question has not been answered yet.
You can Ask your question!
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?
-
North Company has completed all of its operating budgets. The sales budget for the year shows 50,000 units and total sales of $2,250,000. The total unit cost of making one unit of sales is $25....
-
How do the arterioles react when you are running? When you are doing biceps curls? When you are sitting at your desk thinking and doing homework?
-
The problem requires you to use File C03 on the computer problem spreadsheet. Diction Publishing estimates that it needs $500,000 to support its expected growth. The underwriting fees charged by the...
-
At the beginning of Year 2, Better Corporation's accounting equation showed the following accounts and balances: Event Balance BETTER CORPORATION Accounting Equation Assets Liabilities Cash Land...
-
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...
-
Consolidated Software doesnt currently pay any dividends but is expected to start doing so in 4 years. That is, Consolidated will go 3 more years without paying dividends and then is expected to pay...
-
Describe the importance of the manager/employee relationship in the appraisal process. Discuss various forms of bias in performance appraisals. Differentiate between informal and formal performance...
-
What term from Incoterms 2 0 0 0 would you recommend under each of these scenarios? A transaction wherein an American seller is to deliver the goods on board a ship in New York and arrange for export...
-
Which of the following statements regarding the timing of performance appraisals is true? A. a negative performance appraisal given shortly before layoffs or terminations appears to be pretext B. a...
-
Electromagnetic radiation with a wavelength of 531 nm appears as green light to the human eye. The energy of one photon of this light is 3.74 x 10 19J. Thus, a laser that emits 1.3 x 102J of energy...
-
Which individual was responsible for the investigation of the 1849 Cholera epidemic in London? A. William Farr B. Edward Jenner C. John Graunt D. John Snow
-
Direct Method Fill in the blank for each of the following situations. Cash Inflow Balance Sheet Beginning Ending Income Statement (Outflow) 1. Accounts receivable $2,000 $5,000 Sales on account, 2....
-
How can a promoter avoid personal liability for pre-incorporation contracts?
-
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...
-
4. (a) Blackpool Co. exports 90 percent of its total production of goods in New Mexico to Latin American countries. Kakamega Co. sells all the products it produces in the United States, but it has a...
-
Der Company uses a standard cost system in which it applies manufacturing overhead on the basis of direct labor-hours. Two direct labor-hours are required for each unit produced. The budgeted...
-
d.Given the following tableau find an alternative basic feasible optimal solution. Z X1 X2 X3 X4 X5 X5 RHS Z 1 0 0 0 0 2 3 4 X1 0 1 0 2 -1 -1 1 2 X2 0 0 1 -2 1 2 3 2
Study smarter with the SolutionInn App