Mergin two arrays problem.

In this hw problem, we are told that two arrays are already sorted and we need to merge them.

Here is my code:

Code:

int length = a.length+ b.length;

int[] c = new int[length];

for(int i =0; i < a.length; i++)

c[i] = a[i];

for(int j = a.length-1; j < length;j++){

for(int k = 0; k < b.length; k++){

c[j] = b[k];

}

}

java.util.Arrays.sort(c);

return c;

}

The issues given were:

----------------------------------------------------------------

⇒*****Exception java.lang.ArrayIndexOutOfBoundsException: -1

***************occurred

*****⇒*****result[13] is incorrect

*****⇒*****result[2] is incorrect

*****⇒*****result[3] is incorrect

*****⇒*****result[4] is incorrect

*****⇒*****result[5] is incorrect

Fails When:

*****⇒*****arr1[i] == arr21[i]

*****⇒*****arr1[length-1]

-----------------------------------------------------------

I cannot see what is wrong. can anyone help?