hi, I am trying to combine 2 arrays into a sorted one through recursion (no loops alowed)

This is what I've written so far, it is not complete.

Has anyone did it before as I'm having trouble finding it online.

Thanks.

The code:

Code:`public class M4{`

public static int [] merge (int [] ar1,int [] ar2){

int l1 = ar1.length, l2 = ar2.length, l3 = l1+l2;

int result [] = new int [l3];

return merge(ar1,ar2,result,l1,l2,l3);

}

public static int [] merge (int [] ar1, int [] ar2, int [] result, int l1, int l2, int l3){

if (l3 == 0){

if (ar1[0] <= ar2[0]){

if(l2>-1)

l2=l2-1;

else

result [0] =ar1[0];

return result;

}

else{

if(l1>-1)

l1=l1-1;

else

result [0] = ar2[0];

return result;

}}

if (l3>l2 || l3>l1)

result = merge (ar1,ar2,result,l1,l2,l3-1);

result = merge (ar1,ar2,result,l1-1,l2-1,l3-1); //recursive calls

if (ar1[l1] <= ar2[l2]){

if(l2>0)

l2=l2-1;

else

result [l3] = ar1 [l1];

return result;

}

else{

if(l1>0)

l1=l1-1;

else

result [l3] = ar2 [l2];

return result;

}

}

public static void main (String args[]){

int ar1[] = {2,4,6};

int ar2[] = {1,2,2};

merge(ar1,ar2);

}

}