title: Sum and Average of Java Array List Elements
body: <p>I have an exception in my Java program. When I run this code:</p>
  
  <pre><code>ArrayList&lt;Integer&gt; sum = new ArrayList&lt;Integer&gt;();
  sum.add(10);
  sum.add(15);
  sum.add(20);
  int total = 0;
  int avg;
  for(int i = 0; i &lt; sum.size(); i++)
  {
      total += sum.get(i);
      avg = total / sum.size();
      System.out.println("The Average IS:" + avg);
  }
  </code></pre>
  
  <p>It prints each <code>ArrayList</code> index element then prints the average, but when I run this code:</p>
  
  <pre><code>for(int i = 0; i&lt;sum.size(); i++)
      total = total+sum.get(i);
  avg = total / sum.size();
  System.out.println("The Average IS:" + avg);
  </code></pre>
  
  <p>It prints the average, but I have not given the bracket of the <code>for</code> loop.</p>
  
  <p>How does the code compare?</p>