title: calculate the average value across indicies of a hash map
body: <p>I tried writing this code to test out my idea on how to calculate the average value across like indices of a hash map.<br>
  i.e. for each array contained within the hashmap if the first value for the first array was <code>2</code>, and the first value for the second array was  <code>4</code> , and the first value for the third array was <code>3</code>, I want to assign the value of (4+3+2/3)= <code>3</code> to the final double[] array for the first index, and so on for all the indices 2 through n. </p>
  
  <pre><code>    int Size = 3;
  
      double[] AVERAGED_WEIGHTS = new double[Size];
  
      //store weights to be averaged. 
      Map&lt;Integer,double[]&gt; cached_weights = new HashMap&lt;Integer,double[]&gt;();
  
      double[] weights = new double[Size];
  
     int iteration = 0;
     do 
     {
         weights[iteration] = Math.floor(Math.random() * 10000) / 10000;
  
         iteration++;
  
         //store weights for averaging
         cached_weights.put( iteration , weights );  
      } 
      while (iteration &lt; Size);
  
      //calc averages
      for (Entry&lt;Integer, double[]&gt; entry : cached_weights.entrySet()) 
      {
          int key = entry.getKey();
          double[] value = entry.getValue();
          AVERAGED_WEIGHTS[ key - 1 ] +=  value[ key - 1 ]; 
  
          if (key == iteration) 
          {
              AVERAGED_WEIGHTS[ key - 1 ] /= key;
          }
      }
      for(int i = 0; i &lt; weights.length; i++)
      {
         weights[i] = AVERAGED_WEIGHTS[i];
      }
  </code></pre>
  
  <p>This mimics the structure of the original program wherein the weights are populated through a do while loop. This code is broken though and does not sucessfully perform the operation described above. I've been searching online and trying different ways to fix it but I've not been able to solve it. Perhaps someone can spot my faulty logic. </p>