Home Segments Top Top Previous Next

441: Mainline

First, note that you can eliminate the need to call powerOf2 in the simple case in which the value of the parameter is 0:

public static int recursivePowerOf2 (int n) {
 if (n == 0) {
  return 1;  
 } 
 else {return powerOf2(n);} 
}