package codingbat.array2;

/*
 * 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. 
 * 
 * centeredAverage({1, 2, 3, 4, 100}) = 3
 * centeredAverage({1, 1, 5, 5, 10, 8, 7}) = 5
 * centeredAverage({-10, -4, -2, -4, -2, 0}) = -3
 */

public class CenteredAverageTest {

  public static void main(String[] args) {
    CenteredAverageTest test = new CenteredAverageTest();

    System.out.println(">" + test.centeredAverage(new int[] {1, 2, 3, 4, 100})
        + "<");
    System.out.println(">"
        + test.centeredAverage(new int[] {1, 1, 5, 5, 10, 8, 7}) + "<");
    System.out.println(">"
        + test.centeredAverage(new int[] {-10, -4, -2, -4, -2, 0}) + "<");
  }

  public int centeredAverage(int[] nums) {
    return 0;
  }

}

@@ -1062,16 +1062,251 @@
     
-return 0
+int max = nums%5B0%5D;%0A    int min = nums%5B0%5D;%0A    int sum = 0;%0A%0A    for (int num : nums) %7B%0A      sum += num;%0A%0A      if (num %3E max) %7Bmax = num;%7D%0A      if (num %3C min) %7Bmin = num;%7D%0A    %7D%0A%0A    sum = sum - max - min;%0A%0A    return sum / (nums.length - 2)
 ;%0A  

add task centeredAverage