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

To receive full credit programmers must apply coding conventions for code block

ID: 3842842 • Letter: T

Question

To receive full credit programmers must apply coding conventions for code block indentation, comments describing methods/classes, white space between code blocks and variable/method/class naming conventions. Recursion Update Update your program from Assignment 11, Task #2 Write a program that uses an array to find the Average of 10 double values. Use Math random() in combination with a recursive method to fill the array with 10 random values. Then use a different recursive method to iterate through the array summing the total for all 10 double values. Create a third method that will return the mean average from the array. Attach Snipping photos of source code and output.

Explanation / Answer

RecursiveAverage.java

import java.util.Arrays;


public class RecursiveAverage {

   public static void main(String[] args) {
       double arr[]= new double[10];
       fillArray(arr, arr.length);
       System.out.println("Array double values: ");
       System.out.println(Arrays.toString(arr));
       System.out.println("Average is "+getAverage(arr));
   }
   public static void fillArray(double arr[], int size){
       if(size == 0){
           return;
       }
       else{
           arr[size-1] = Math.random();
           fillArray(arr,size-1);
       }
   }
   public static double getSum(double arr[], int size) {
       if(size == 0){
           return 0;
       }
       else{
           return arr[size-1] + getSum(arr, size-1);
       }
   }
   public static double getAverage(double arr[]) {
       return getSum(arr, arr.length)/arr.length;
   }
}

Output:

Array double values:
[0.2044773806382031, 0.47934212155535094, 0.756325175975389, 0.949386138390275, 0.5281888979568297, 0.9788819687792328, 0.26552448046021726, 0.6623709280009201, 0.42402610910169936, 0.24997630185241737]
Average is 0.5498499502710533

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