Write a program to create two SDAs in order to store 5 numbers and 6 numbers respectively, then merge the values of both the arrays into third array so that the values of first array will be kept first from left to right followed by the values of second array, again from left to right, then display values of the merged array.
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] a = {5, 6, 9, 4, 2};
int[] b = {10, 0, 98, 1, 3, 5};
int[] c = new int[a.length + b.length];
for (int i = 0, j = 0, k = 0; i < c.length; i++) {
c[i] = i < a.length ? a[j++] : b[k++];
}
System.out.println(Arrays.toString(c));
}
}
Comments
Leave a comment