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

What is the code I need to cast sum / numbers.length from int to double here? ca

ID: 3816329 • Letter: W

Question

What is the code I need to cast sum / numbers.length from int to double here?

calculate Average method First, find the sum of all values in the numbers array. Return the sum divided by the number of elements in the array. Remember that sum and numbers. length are both type int so you need to do a cast before you divide. For this acitivity, you can assume that number. Length is not equal to zero. Compile Scores and run the following code in the interactions pane. Be sure to drag avg from the workbench onto the canvas

Explanation / Answer

Hi, Please find my implementation.

Please let me know in case of any issue.

double calculateAverage(int[] numbers){

      

       int sum = 0;

       for(int i=0; i<numbers.length; i++)

           sum = sum + numbers[i];

      

       return (double)sum/(double)numbers.length;

   }

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