Question: 3 0 . 5 . 1 : Write a recursive method to compute a power of two. 5 9 7 7 1 4 . 2

30.5.1: Write a recursive method to compute a power of two.
597714.2988516.qx3zqy7
In order to compute a power of two, you can take the next-lower power and double it. For example, if you want to compute 211 and you know that 210=1024, then 211=21024=2048. Write a recursive method
public static int pow2(int n)
where n is the exponent, that is based on this observation. If the exponent is negative, return -1.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!