//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 4.03 on page 85
//  Recursive Function returns sum of first n elements of an array

public class Pr0403
{ public static void main(String[] args)
  { double[] x = {88.8,-11.1,22.3,-2,5,-5,6,-7,8,-9};
    System.out.print("x = {");
    for (int i = 0 ; i < 10 ; i++)
    {  System.out.print(x[i]) ;
       if ( i < 9 ) System.out.print(", ");
    }
    System.out.println("}");
    for ( int n = 0 ; n < 10 ; n++ )
      System.out.println("sum(x,"+n+") = " + sum(x,n) ) ;
  }
  public static double sum(double[] a, int n)
  { if (n==0) return 0.0;       // basis
    return sum(a,n-1) + a[n-1];  // recursion
  }

}
