Question: Implement the static neighborAverage method, which takes an array of ints called nums, and returns an array containing the averages of sequences of three

Implement the static neighborAverage method, which takes an array of ints called 

Implement the static neighborAverage method, which takes an array of ints called nums, and returns an array containing the averages of sequences of three adjacent neighbors from the nums array. I.e., the first element (index 0) of the resulting array will be the average of the first three values in nums (at indices 0, 1, and 2), the second element will be the average of the fourth through sixth values, etc. The resulting array should be the exact size to store these results (so any Os in the resulting array would come from an average value that is 0). Please note the precondition below to make this problem easier. Here are some examples (answers shown below are not exact with respect to roundoff errors in Java): nums [-1, -1, -4] [5, 5, 5, 1, 3, 2, 3, 0, 0] neighborAverage (nums) [-2.0] [5.0, 2.0, 1.0] [3.33334, 3.33334] does not satisfy the precondition handle this case. -you do not have to [2, 4, 4, 5, 3, 2] [1, 2, 3, 4] // PRE: the length of nums is > 0 and is a multiple of three public static double () neighborAverage (int ( ) nums) {

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!