Created
December 9, 2017 10:52
-
-
Save harshityadav95/93926a20a386a54b6d37228f6426467a to your computer and use it in GitHub Desktop.
/* Return the "centered" 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 …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Return the "centered" 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. | |
*/ | |
static int centeredAverage(int[] inputIntArray) { | |
Arrays.sort(inputIntArray); | |
int c= 0,s=0; | |
for (int i = 1; i < inputIntArray.length - 1; i++) | |
{ | |
s+= inputIntArray[i]; | |
c++; | |
} | |
return (s/c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment