title: How to find the geometric mean of an array of ints using Math.pow
body: <p>I am attempting to find the geometric mean of a small array of integers using Math.pow.
  This is my first time using this syntax and I am not sure how to go about finishing my code.</p>
  
  <p>I am currently going through last years exam papers and this is one of the questions.</p>
  
  <p>Please forgive any errors in my code. I am still learning Java.</p>
  
  <pre><code>public class AverageOfArray {
  
  public static void main(String []args){
  
      int [] data = new int[3];
      data[0] = 2;
      data[1] = 4;
      data[2] = 8;
  
      int y = 0;
      int sum = 0;
      for(int i = 0; i &lt; data.length; i++){
          sum = sum + data[i];
          y++;
      }
  
      Math.pow(sum, 1.0/data.length);
      System.out.println(sum);
  
  }
  
  }
  </code></pre>
  
  <p>Although the code runs fine without error, it is not giving me the output I require. The mean should be 4.</p>
  
  <p>Here is the code after some edits:</p>
  
  <pre><code>public class AverageOfArray {
  
  public static void main(String []args){
  
      int [] data = new int[3];
      data[0] = 2;
      data[1] = 4;
      data[2] = 8;
  
  
      double sum = 1.0;
  
      for(int i = 0; i &lt; data.length; i++){
          sum = sum * data[i];
      }
  
      double geoMean = Math.pow(sum, 1.0/data.length);
      System.out.println(geoMean);
  
  }
  
  }
  </code></pre>
  
  <p>However it is now returning 3.9999996? 
  Am I looking at Math.abs here now?</p>