Question
ADD SOURCE CODE TO THE FOLLOWING PROGRAM TO EXPLAIN CODE: import java.util.Arrays; public class RecursiveAverage { public static void main(String[] args) { double arr[]= new
ADD SOURCE CODE TO THE FOLLOWING PROGRAM TO EXPLAIN CODE:
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; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started