public class armrege {
public int[] insert(int a[], int b[], int offset) {
int i;
int []c=new int[a.length + b.length]; //declaring new array of length equals size of a + size of b
//insert first half of array a
for( i=0;i<offset;i++) {
c[i]=a[i];
}
//after inserting first half of array a insert complete b from offset
int j=0;
for(i=offset;i<offset+b.length;i++) {
c[i] = b[j];
j++;
}
j=offset;
// after inserting b insert other half of array a
for(i=offset+b.length;i<a.length + b.length;i++) {
c[i]=a[j];
j++;
}
return c;
}
public static void main(String[] args) {
int a[] = {1,2,3,4};
int b[] = {13,14};
int offset = a.length/2; // offset for finding the middle index of array a
armrege ob = new armrege(); //create oblect of class
int c[] = ob.insert(a,b,offset); // calling non static function with the object
for(int i=0;i<c.length;i++) {
System.out.print(c[i]+” “); // printing array result
}
}
}
//output
// 1 2 13 14 3 4