Write a method that takes 3 double arrays, merges all 3 arrays and returns a new array which stores all the values of the 3 arrays.
Please use Java and comment the code thank you
//Java program
public class ThreeMerge {
public static void main(String args[]) {
double arr1[] = {1,3};
double arr2[] = {2,5};
double arr3[] = {4,8};
double arr[] =
mergeThree(arr1,arr2,arr3);
for(int
i=0;i<arr.length;i++)
System.out.print(arr[i]+" ");
}
//function to merge three array
private static double[] mergeThree(double[] arr1,
double[] arr2, double[] arr3) {
int l1=arr1.length;
int l2 = arr2.length;
int l3 = arr3.length;
double A[] = new
double[l1+l2];
merge(arr1,arr2,A);
double B[] = new
double[l1+l2+l3];
merge(arr3,A,B);
return B;
}
//function to merge two array at a time into third
array
public static void merge(double [] A ,double
B[],double C[]) {
int first1= 0;
int last1= A.length;
int first2 = 0;
int last2 = B.length;
int index=0;
while(first1<last1 && first2<last2)
{
if(A[first1]<B[first2]) {
C[index] =
A[first1];
first1++;
}
else {
C[index] =
B[first2];
first2++;
}
index++;
}
while(first1<last1) {
C[index] = A[first1];
first1++;
}
while(first2<last2) {
C[index] = B[first2];
first2++;
}
}
}
//sample output
Write a method that takes 3 double arrays, merges all 3 arrays and returns a new...
1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...
3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...
JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...
write a c++ program that merges two arrays a and b. You may use the following array contents A=5,7,8,6,3,3 and B=4,5,6,1,2,3.The merged array should exclude all repeating numbers
Write a static method that takes an array of Strings and returns a double. Determine the average number of characters for the Strings assigned to the array. Return the average.
Write a method named avgLength which takes an array of Strings as an input parameter and returns a double. The method should calculate and return the average length of all the strings in the array (in java langauge)
Write a method public static ArrayList merge(ArrayList a, ArrayList b) that merges two array lists, alternating elements from both array lists. If one array list is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer array list. For example, if a is 1 4 9 16 and b is 9 7 4 9 11 then merge returns the array list 1 9 4 7 9 4 16 9 11...
Need help with java code, this is all in a method 1) 3 different arrays are brought in 2) I create local array called arrayWithLargestValues which is the size of the largest array from the 3 brought in 3) I need to somehow fill the local 'arrayWithLargestValues' with the all different largest values from the 3 different arrays hopefully I made sense sample input/output int [ ] arrayWithLargestValues = new int [ ] // this has to be set to...
3. Write a method buildString which takes a 2D array of characters (char), and returns a string that is built from all the characters in that array. For example, the following method call should return "hello!" buildString( new char[] [ 'h', 'e',
java code Write a method called reverse that takes an array of integers as an input and returns the same values in reverse order as the output. Test your method in the main.