I keep getting the Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException error
<p>I get the runtime error:</p>

<pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at Series.series(Series.java:10)
at Series.main(Series.java:21)
</code></pre>

<p>in lines 10 and 21 and can't figure out what's wrong. I am trying to make the program sum the series 1 - 2x + 3x^2 + 4x^3... n*x^(n-1). Any help I can get would be much appreciated!</p>

<pre><code>public class Series {

public static double series (double x, int n) {

    int increase = n;
    double sign = Math.pow(-1.0, increase+1);
    double exponent = Math.pow(x, increase-1);
    double[] A = new double[n];
    for (int i = 0; i &lt;= n; i++) {
        A[i] = (sign) * ((increase + 1) - A.length) * (exponent); increase = increase + 1;
    }
    double sum = 0;
    for (int i = 0; i &lt; A.length; i++) {
            sum = sum + A[i];
        }
    return sum;
}

public static void main (String[] args) {
    System.out.print("series(0.5, 1)  should be  1.0");
    System.out.println(" : " + series(0.5, 1));
}
}
</code></pre>
