Java 递归1


Java 递归

public class PowerTest {

   public static void main(String[] args) {

      int base = 3, power = 4;

      int result = power(base, power);

      System.out.printf("the power is "+result);

   }

   public static int power(int base, int power) {

      if (power != 0)

         return (base * power(base, power - 1));

      else

         return 1;

   }

}