Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CODE IN JAVA: Please show the output code and code with commenting please! Given an array a of n numbers, consider the problem of computing
CODE IN JAVA:
Please show the output code and code with commenting please!
Given an array a of n numbers, consider the problem of computing the average of the first i numbers, for i ranging from 0 to n - 1. That is, compute the array b of length n, where Let us assume that all numbers are integer, and so averages are computed with no fractional part; for example, (2+5+1)/3-2. We call b the array of prefix averages of a. Write a program to compute the maximum of the prefix averages of a set of input numbers. Call your program MaxPrefixAverage. The input consists of two lines. The first line contains a single positive integer n, and the second line contains n integers separated by spaces. The output is a single integer Your program should use O(1) memory; in particular, it may not use an array of length proportional to n For example, if the input is 3 1 74 6 then the correct output is 4 This is because the prefix averages are: 3/1 - 3, (3 +1)/2 - 2, (3+1+ 7)/3-3, (3+1+7+4)/4 3, and (3+1+7+4+6)/5-4. The maximum of these numbers is 4Step 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