import java.util.Arrays; public class MergeSortedArrays { public static void main(String[] args) { int[] a = {1, 3, 5, 7, 9}; int[] b = {2, 4, 6, 8, 10}; int[] merged = mergeSortedArrays(a, b); System.out.println("Merged sorted array: " + Arrays.toString(merged)); } static int[] mergeSortedArrays(int[] a, int[] b) { int[] result = new int[a.length + b.length]; int i = 0, j = 0, k = 0; while (i < a.length && j < b.length) { if (a[i] <= b[j]) result[k++] = a[i++]; else result[k++] = b[j++]; } while (i < a.length) result[k++] = a[i++]; while (j < b.length) result[k++] = b[j++]; return result; } }