Write a program to create 2 arrays in order to store 5 numbers and 6 numbers respectively. Then merge those values of both the array into third array so that the values of the first array will be kept first from left to right followed by values of second array again from left to right. Then display those values of the merged(third) array.
import java.util.Arrays;
class Main {
public static void main(String[] args) {
int[] arr1 = {23, 45, 12, 78, 4};
int[] arr2 = {77, 11, 45, 88, 32, 56};
int[] result = new int[arr1.length + arr2.length];
System.arraycopy(arr1, 0, result, 0, arr1.length);
System.arraycopy(arr2, 0, result, arr1.length, arr2.length);
System.out.println(Arrays.toString(result));
}
}
Comments
Leave a comment