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: 3842777 • 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. 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

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class RecussionArrayAddition
{
public double sumOfArray(double[] a, int n) {

if (n == 0)
return a[n];
else
return a[n] + sumOfArray(a, n-1);
}

public double Average(double sum, int n)
{
    double average;
   
    average=sum/n;
    return average;
}


public static void main (String[] args) throws java.lang.Exception
   {
       double[] a = new double[10];
       double val;
   RecussionArrayAddition objArray=new RecussionArrayAddition();
  
   for(int i=0;i<10;i++)
   {
       Random rand = new Random();

val = rand.nextGaussian();
a[i]=val;
      
   }
  

Output:

  
double sum = objArray.sumOfArray(a, a.length-1);
  
System.out.println("Sum Is"+sum);
  
double average=objArray.Average(sum,10);
System.out.println("Average Is"+average);
  
   }
}

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