Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

File above contains an incomplete program. The goal of the program is to compute

ID: 3680613 • Letter: F

Question

File above contains an incomplete program. The goal of the program is to compute the position-wise maxima of two arrays. Complete that program, by defining an array_max function, that satisfies the following specs:

-Function array_max takes two arguments, called A, B. They are both arrays of double numbers.

-If the two arrays do NOT have the same length, function array_max should return null.

-Otherwise, the function should return an array called result, with length equal to the length of A, such that the value at position i of result is the larger among the values at position i of A and B.

IMPORTANT: You are NOT allowed to modify in any way the main function.

The complete program should produce this output:

Explanation / Answer

public int [] array_max(double []A, double []B)
{
   if(A.length != B.length)
       return null;
   else{
       int []result=new int[A.length];
       for(int i=0;i<result.length;i++){
           if(A[i]>B[i])
               result[i]=A[i];
           else
               result[i]=B[i];
       }
       return []result;
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote