Answer to Question #289251 in Java | JSP | JSF for Merger

Question #289251

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.


1
Expert's answer
2022-01-20T16:20:43-0500
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));
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog