title: Calculating average of an array list?
body: <p>I'm trying to use the below code to calculate the average of a set of values that a user enters and display it in a <code>jTextArea</code> but it does not work properly. Say, a user enters 7, 4, and 5, the program displays 1 as the average when it should display 5.3  </p>
  
  <pre><code>  ArrayList &lt;Integer&gt; marks = new ArrayList();
    Collections.addAll(marks, (Integer.parseInt(markInput.getText())));
  
    private void analyzeButtonActionPerformed(java.awt.event.ActionEvent evt) {
        analyzeTextArea.setText("Class average:" + calculateAverage(marks));
    }
  
    private int calculateAverage(List &lt;Integer&gt; marks) {
        int sum = 0;
        for (int i=0; i&lt; marks.size(); i++) {
              sum += i;
        }
        return sum / marks.size();
    }
  </code></pre>
  
  <p>What is wrong with the code?</p>