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

Write a static method complete with a header line that has two integer array arg

ID: 3758136 • Letter: W

Question

Write a static method complete with a header line that has two integer array arguments, A and B. The arrays may have different lengths. Determine the average of the values in array A.   Also determine the average of the values in array B. Your function should return the larger of the two average values.

Use nested loops to generate the output for each of the two shapes:

&&&&       and        &

&&&                  &&

&&                  &&&

   &                  &&&&

Explanation / Answer

public static int largerArrayMean(int a[],int b[]){
   int sumA = 0,sumB = 0;
   for(int i = 0; i < a.length; i++)
       sumA += a[i];
   for(int i = 0; i < b.length; i++)
       sumB += b[i];
   return sumA/a.length > sumB/b.length ? sumA/a.length : sumB/b.length;
}
public static void pattern(int n){
   for(int i = n ; i > 0; i--)
   {
       print(i,n-i);
   }
}
public static void print(int n,int spaces){
   for(int i = 0; i < spaces; i++)
       System.out.print(" ");
   for(int i = 0; i < n; i++)
       System.out.print("&");
   System.out.println();
}

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