//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 4.06 on page 85
//  Recursive Function that returns nth power of x

public class Pr0406
{ public static void main(String[] args)
  { double x ;
    int n ;
    int power ;
    for ( int count = 0 ; count < 10 ; count++ )
    {  x =  Math.round(Math.random()*10.0) ;
       n =  (int)(Math.round(Math.random()*10));
       System.out.println("pow("+x+","+n+") = " + pow(x,n) );
    }  }
  public static double pow(double x, int n)
  { if (n==0) return 1.0;    // basis
    return x*pow(x,n-1);     // recursion
  }
}
