int[] a = { 1, 3, 5, 7, 9,11 ,12};
int[] b = { 2, 3, 4, 6, 8, 10,33 };
int[] c=new int[a.length+b.length];
int temp=0;
int aindex = 0;
int bindex = 0;
while (aindex < a.length && bindex < b.length) {
if (a[aindex] == b[bindex]) {
System.out.print(a[aindex]+" "+b[bindex]+" ");
c[temp++]=a[aindex];
c[temp++]=b[bindex];
aindex++;
bindex++;
} else if (a[aindex] < b[bindex]) {
System.out.print(a[aindex]+" ");
c[temp++]=a[aindex];
aindex++;
} else {
System.out.print(b[bindex] + " ");
c[temp++]=b[bindex];
bindex++;
}
}
while (aindex
System.out.print(a[aindex] + " ");
c[temp++]=a[aindex];
aindex++;
}
while (bindex
System.out.print(b[aindex] + " ");
c[temp++]=b[bindex];
bindex++;
}
System.out.println("\n"+Arrays.toString(c));