Average Salary Excluding the Minimum and Maximum Salary in Java
Average Salary Excluding the Minimum and Maximum Salary in Java.
public double average(int[] salary) {
int i;
int big = salary[0];
int small = salary[0];
double sum = salary[0];
for (i = 1; i < salary.length; i++) {
sum += salary[i];
big = (big > salary[i]) ? big : salary[i];
small = (small < salary[i]) ? small : salary[i];
}
return ((sum-big-small)/(i-2));
}
Comments
Post a Comment