code: public static double sum(double[] a, int fromIndex, int toIndex) {
      double result = 0.0;
      for (int i = fromIndex; i < toIndex; i++) {
        result += a[i];
      }
      return result;
    }
docs: Returns the sum of the portion of an array of numbers between
  <code>fromIndex</code>, inclusive, and <code>toIndex</code>, exclusive.
  Returns 0 if <code>fromIndex</code> &gt;= <code>toIndex</code>.