Hi, I am trying to divide array elements in low and high using a single for loop. But, I don't know why I am getting ArrayIndexOutOfBoundsException. I tried working it out on paper and it seems correct. Can anyone point out my mistake?
Thanks!!

for(int i=0;i<=n/2;i++)
{
    ALow[i]=A[i];
    AHigh[i]=A[i+n/2];

}

Hi, I am trying to divide array elements in low and high using a single for loop. But, I don't know why I am getting ArrayIndexOutOfBoundsException. I tried working it out on paper and it seems correct. Can anyone point out my mistake?
Thanks!!

for(int i=0;i<=n/2;i++)
{
    ALow[i]=A[i];
    AHigh[i]=A[i+n/2];

}

Too little info. We don't know what n is. We don't know what indexes A[], ALow[] and AHigh[] are defined for. If n is even and A[] is defined for n elements, then its valid indexes would be 0 through n - 1. When i is equal to n / 2, i + n / 2 equals n / 2 + n / 2 = n, so A[i+n/2] = A[n] would be out of bounds since the highest legal index would be n - 1.

But that's just speculation. We'd have to see the rest of the code and possibly run the code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.