В методе слияния mergeArrays в условии сравнения выскакивает ошибка ArrayIndexOutOfBoundsException. Почему?
public class Main {
public static void main(String[] args) {
int[][] commamds =
{{45, 31, 24, 22, 20, 17, 14, 13, 12, 10},
{31, 18, 15, 12, 10, 8, 6, 4, 2, 1},
{51, 30, 10, 9, 8, 7, 6, 5, 2, 1}};
int[] common = mergeArrays(commamds[0], commamds[1], commamds[2]);
for (int i = 0; i < common.length; i++) {
System.out.print(common[i] + " ");
}
}
public static int[] mergeArrays(int[] A, int[] B, int[] C){
int[] res = new int[A.length+B.length+C.length];
int ia =0,ib = 0,ic =0, ires =0;
while(ia< A.length||ib< B.length||ic< C.length){
if(ia==A.length&& ib==B.length){
res[ires] = C[ic];
ic++;
}else if(ia == A.length&&ic == C.length){
res[ires] = B[ib];
ib++;
}else if(ib == B.length&& ic == C.length){
res[ires] = A[ia];
ia++;
}else if(A[ia]>=B[ib] && A[ia]>=C[ic]){**//здесь ArrayIndexOutOfBoundsException.Не пойму где ошибка.**
res[ires] = A[ia];
ia++;
}else if(B[ib]>=A[ia]&&B[ib]>=C[ic]){
res[ires] = B[ib];
ib++;
}else{
res[ires] = C[ic];
ic++;
ires++;
}
}
return res;
}
}