title: Finding mean of elements in array and comparing mean to closest number element in array
body: <p>having some issues with comparing my mean element of my 2d array to the closest element value to the mean. The main issue is i'm not sure how to proceed beyond using math.abs to compare the array elements to the mean.</p>
  
  <p>My code.</p>
  
  <pre><code>public class exercise_2{
  public static int[] closestToMean (double[][] array)
  {
      int sum = 0;
      for (int i=0; i &lt; array.length; i++)
  {
          for (int j=0; j &lt; array.length; j++)
      {
          sum += array[i][j];
      }
  }
      double mean = (double) sum / array.length;
      System.out.println("Mean = " + mean);
      //calculate mean of array elements i + j
  
  
      //closest to mean
      int distance = Math.abs(array[0] - mean);
      int i = 0;
      for (int c = 1; c &lt; array.length; c++)
      {
          int cdistance = Math.abs(array[c] - mean);
          if (cdistance &lt; distance)
          {
              i = c;
              distance = cdistance;
          }
      }
      double mean = array[i];
      System.out.println("Closest array element = " + mean);
      //print closest to mean array element
  }
  
  public static void testClosestToMean()
  {
      exercise_2 ex2 = null;
      ex2.closestToMean();
      //invoke method closestToMean()
  }
  
  public static void main()
  {
      exercise_2 ex2 = null;
      ex2.testClosestToMean();
      //invoke testClosestToMean()
  }
  </code></pre>
  
  <p>}</p>