Answer to Question #289534 in Java | JSP | JSF for ____

Question #289534

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.

1
Expert's answer
2022-01-22T02:41:52-0500
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));
    }
}

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