-1

Here's the prompt: Return an array of 13 doubles with the sines of the integers -6 to 6 in order.

I keep getting an ArrayIndexOutOfBoundsException: 13 (line:4) error. How do I fix it?

Here's my code:

public double[] thirteenSines(){
double[] arr = new double [13];
for(int i = -6; i < arr.length; i++)
    arr[i + 6] = Math.sin(i);
  return arr;
}

Any help is greatly appreciated!

kiwu2
  • 7
  • 1
  • 2

1 Answers1

0

The array length is 13. So when you get to 7, it goes out of bounds with 7 + 6.

Gama
  • 141
  • 4