Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the following method: public double power(double x, int n) { System.out.pr

ID: 3608341 • Letter: G

Question

Given the following method: public double power(double x, int n) {       System.out.println( "Inpower " + x + "    : "+ n);       if ( n ==0)             return1.0;       else if( n % 2 !=0)             returnx * Math.pow(power(x, n/2), 2);       else             returnMath.pow(power(x,n/2), 2); } What is output by the callSystem.out.println(power(2.0,13));? Given the following method: public double power(double x, int n) {       System.out.println( "Inpower " + x + "    : "+ n);       if ( n ==0)             return1.0;       else if( n % 2 !=0)             returnx * Math.pow(power(x, n/2), 2);       else             returnMath.pow(power(x,n/2), 2); } What is output by the callSystem.out.println(power(2.0,13));?

Explanation / Answer

Output will be : In power 2.0    : 13 In power 2.0    : 6 In power 2.0    : 3 In power 2.0    : 1 In power 2.0    : 0 8192.0 //here is trace of calledfunction.     Calling power(2.0,13)     Printing ... In power2.0    : 13     return x * Math.pow(power(x, n/2), 2)         Calling power(2.0,6)         Printing ...In power 2.0    : 6         return x *Math.pow(power(x, n/2), 2)            Calling power(2.0,3)            Printing ... In power 2.0    :3            return x * Math.pow(power(x, n/2), 2)                Calling power(2.0,1)                Printing ... In power 2.0    :1                return x * Math.pow(power(x, n/2), 2)                    Calling power(2.0,0)                    Printing ... In power 2.0    :0                    return 1, n==0 8192.0       //print by System.out.print

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote