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
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (1 review)
Based on the given Java program the power function computes x raised to the power of n using recursi...View the full answer
Answered By
Charles mwangi
I am a postgraduate in chemistry (Industrial chemistry with management),with writing experience for more than 3 years.I have specialized in content development,questions,term papers and assignments.Majoring in chemistry,information science,management,human resource management,accounting,business law,marketing,psychology,excl expert ,education and engineering.I have tutored in other different platforms where my DNA includes three key aspects i.e,quality papers,timely and free from any academic malpractices.I frequently engage clients in each and every step to ensure quality service delivery.This is to ensure sustainability of the tutoring aspects as well as the credibility of the platform.
4.30+
2+ 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
-
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?
-
If the time remaining to complete a job is 10 days and the lead time remaining is 12 days, what is the critical ratio? Is the order ahead of schedule, on schedule, or behind schedule?
-
In each case, graph the line that passes through the given points. a. (2, 2) and (7, 7) LO9 b. (0, 7) and (7, 0) c. 1 -2, 32 and (6, 4) d. 1 -5, -32 and (3, 4)
-
During the month of June, Bench Co. had cash sales of $300,000 and credit sales of $180,000, both of which include the 8% sales tax that must be remitted to the state by July 15. Instructions Prepare...
-
What different graphs are available in QuickBooks Accountant? After discussing the different graphs available, choose two graphs to provide in-depth information on their contents? Why are graphs...
-
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...
-
Lee Chang opened Lees Window Washing on July 1, 2024. In July, the following transactions were completed: July 1 Lee invested $20,000 cash in the business. 1 Purchased a used truck for $25,000,...
-
An employer has calculated the following amounts for an employee during the last week of June 2021. Gross Wages $1,800.00 Income Taxes $414.00 Canada Pension Plan $94.00 Employment Insurance $28.00...
-
Section Two: CASE ANALYSIS (Marks: 5) Please read the following case and answer the two questions given at the end of the case. Zara's Competitive Advantage Fashion houses such as Armani and Gucci...
-
The activity of carbon in liquid iron-carbon alloys is determined by equilibration of CO/CO2 gas mixtures with the melt. Experimentally at PT = 1 atm, and 1560C (1833 K) the equilibrated gas...
-
Apply knowledge of concepts and theories covered in the course to leader - the leader can either be themselves if they lead a team, someone real and personally known to them (such as a boss or leader...
-
A resistor in a dc circuit R = 1.2 2. The power dissipated P is a second-degree function of the voltage V. Graph P versus V from V = 0.0 V to V = 3.0 V.
-
The amount of pressure required to sink a large, heavy object in a soft homogeneous soil that lies above a hard base soil can be predicted by the amount of pressure required to sink smaller objects...
-
The landing gear of an aircraft with: mass of 2000 kg the spring-mass-damper system Consider that the runway surface is y(t) = 0.2 cos 157.08t stiffness of the spring is 5 x 105 N/m. What is the...
-
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?
-
Create a Data Table to depict the future value when you vary the interest rate and the investment amount. Use the following assumptions: Interest Rates: Investment Amounts:-10.0% $10,000.00 -8.0%...
-
Isaac earns a base salary of $1250 per month and a graduated commission of 0.4% on the first $100,000 of sales, and 0.5% on sales over $100,000. Last month, Isaac's gross salary was $2025. What were...
-
Calculate the price, including both GST and PST, that an individual will pay for a car sold for $26,995.00 in Manitoba. (Assume GST = 5% and PST = 8%) a$29,154.60 b$30,234.40 c$30,504.35 d$28,334.75...
Study smarter with the SolutionInn App