Question
Return the centred average of an array of ints, which we'll say is the mean average of the values, except ignoring the largest and smallest
Return the "centred" average of an array of ints, which we'll say is the mean average of the values, except ignoring the largest and smallest values in the array. If there are multiple copies of the smallest value, ignore just one copy, and likewise for the largest value. Use int division to produce the final average. You may assume that the array is length 3 or more. centredAverage([1, 2, 3, 4, 100]) 3 centredAverage([1, 1, 5, 5, 10, 8, 7]) 5 centredAverage([-10, -4, -2, -4, -2, 0]) -3
For example:
Test | Result |
---|---|
int[] nums = {16, -8, -18, 20, -15, 13, 4, 14, -8, -19, 9, 14, 6, 1, -9}; System.out.println(centredAverage(nums)); | 1 |
just write the body, start with
public int centredAverage(int[] nums) { // TODO your code goes here }
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