Trace the program in Fig. 8.1 for (x=2) and (n=5) and draw the tree similar to the
Question:
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.
Transcribed Image Text:
import java.util.*; class Ch8Samplel { public static void main(String[] args) { Scanner scanner; scanner= new Scanner (System.in); int x, n, answer; System.out.printin(); System.out.print ("Enter an integer for x: "); x= scanner.nextInt (); System.out.print ("Enter an integer for n: "); n scanner.nextInt (); System.out.println(); if (x>=0 && n>=0 && ! (x== 0 && n==0)) { answer = power(x, n); System.out.println("The answer is " + answer); } else System.out.println ("Power not calculated"); } public static int power (int x, int n) { int answer; if (n > 0) else answer power (x, n-1) *x; answer 1; 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
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
-
In a displacement reaction, we a cation (either H" or a metal cation) with an elemental metal (turning the metal into a cation and the original cation into its elemental form). To know whether a...
-
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...
-
On being heated with sulfur trioxide in sulfuric acid, 1, 2, 4, 5-tetramethylbenzene was converted to a product of molecular formula C10H14O3S in 94% yield. Suggest a reasonable structure for this...
-
Two kg water at 200 kPa with a quality of 25% has its temperature raised 20oC in a constant pressure process. What is the change in enthalpy?
-
Edington Electronics Inc. produces and sells two models of pocket calculators, XQ-103 and XQ-104. The calculators sell for $15 and $25, respectively. Because of the intense competition Edington...
-
What prevents food from going into the trachea after it is swallowed?
-
Create a memo describing your initial analysis of the situation at FAME as it relates to the design of the database application. Write this as though you are writing a memo to Martin Forondo. Ensure...
-
Describe the relationship between the governmental agencies (SEC and Federal Reserve) and the banks (Bank of America, JP Morgan, Merrill Lynch, Wachovia etc. How did they view their responsibilities?...
-
Trace the program in Fig. 8.10 for \(n=5\) and draw the tree similar to the one in Fig. 8.21 . import java.util..; class Ch8Sample2 { public static void main(String[] args) { Scanner scanner;)...
-
Consider the program in Fig. 8.10 where Lines 22 and 23 are swapped. Draw a series of contour diagrams to show the state of execution for \(n=3\). import java.util.*; class Ch8Sample2 ( public static...
-
What are the factors contributing to the trend toward fair value accounting?
-
Examine current performance appraisal research and the focus on the social-psychological context of work performance appraisal. How does social-context impact performance appraisal and feedback for...
-
A spherical shell contains three charged objects. The first and second objects have a charge of -11.0 nC and 35.0 nC, respectively. The total electric flux through the shell is -743 N.m/C. What is...
-
This figure shows a sinusoidal wave that is traveling from left to right, in the +x-direction. Assume that it is described by a frequency of 24.9 cycles per second, or hertz (Hz). 5.90 cm (a) What is...
-
(a) A researcher connects a 8.50 V battery to the plates of a capacitor. After waiting a while, the capacitor reaches a maximum amount of 17.0 C of stored charge. What is the value of the capacitance...
-
A high-speed photograph of a club hitting a golf ball is shown in the figure below. Ted Kinsman/Photo Researchers, Inc. The club was in contact with a ball, initially at rest, for about 0.0017 s. If...
-
For each of the following items, indicate whether it would appear on a statement of cash flows prepared using the direct method (D) or the indirect method (I). ______ 1. Net income ______ 2. Increase...
-
Air pollution generated by a steel mill is an example of a) a positive production externality. b) a negative production externality. c) a public good. d) the free-rider problem. State and local taxes...
-
Modify the Stock class definition (the version in stock20.h) so that it has member functions that return the values of the individual data members. A member that returns the company name should not...
-
You can describe a simple list as follows: The simple list can hold zero or more items of some particular type. You can create an empty list. You can add items to the list. You can determine whether...
-
What is a default constructor? What is the advantage of having one?
-
Read this case study and then respond with how you would handle this situation: Randy is a person who frequently offends others due to his honest and open expression. He oftentimes says things...
-
Flextrola, Inc., an electronic systems integrator, plans to design a key component for its next-generation product with Solectrics. Flextrola will integrate the component with some software and then...
-
Assume that Blue Spruce Gems uses the specific identification cost flow method. (1) How could Blue Spruce maximize its gross profit for the month by specifically selecting which diamonds to sell on...
Study smarter with the SolutionInn App