Menu

[Solved]Java Write Program Merge Two Sorted Arrays Third Array Ask User Enter Size Two Arrays Leng Q37283506

in java

Write a program to merge two sorted arrays into a third array.Ask the user to enter the size of the two arrays. The length ofarray1 could be greater than, equal to or less than the length ofarray2.

Fill both with random numbers 0-99. Sort both arrays asexplained below. Write a method merge that takes the two arrays asarguments. The method returns a merged array with size equal to thesize of both arrays combined.

Note: You may not create the third array and then sort it. Thetwo arrays passed as arguments must be sorted.

To sort an array, java.util.Arrays is a library that has amethod sort that sorts an array. To use it, you will need to importjava.util.Arrays.
Arrays.sort(array); // will sort array in ascending order

Example:
Enter the size of array1: 10
Enter the size of array2: 4
Array1: 7 2 3 8 6 6 75 38 3 2 Array2: 5 4 3 2
Sort the two arrays
Array1: 2 2 3 3 6 6 7 8 38 75 Array2: 2 3 4 5
Merging
Array3: 2 2 2 3 3 3 4 5 6 6 7 8 38 75

Expert Answer


Answer to in java Write a program to merge two sorted arrays into a third array. Ask the user to enter the size of the two arrays… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *