//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 4.02 on page 85
//  Recursive Function returns sum of first n powers of b


public class Pr0402
{ public static void main(String[] args)
  { for ( double b = -2; b < 2.5 ; b += 0.5 )
    { for (int n = 0 ; n < 6; n++)
       System.out.print("\t"+ sum(b,n));
      System.out.println();
    }
  }
  public static double sum(double b, int n)
  { if (n==0) return 1;       // basis
    return 1 + b*sum(b,n-1);  // recursion
  }

}
