title: Linked List Iterator adds too many numbers
body: <p>I wrote a program for my Java class and I can't seem to figure out what it is doing wrong. I populate a LinkedList with 25 random integers between 1 and 100. I then sort the list and output the sum and average. Then I remove the odd numbers and output the sum and average of the new list. However, when I do the final calculations it also seems to add the largest number from the original list as well. If the largest number from the first list is even it adds it twice.</p>
  
  <pre><code>import java.util.Collections;
  import java.util.Random;
  import java.util.List;
  import java.util.LinkedList;
  import java.util.ListIterator;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.Collection;
  import java.util.*;
  
  
  public class randomNumberCollection
  {
  public static void main(String[] args)
  {
      int count = 0;
  
      //Create LinkedList object
      LinkedList&lt;Integer&gt; numList = new LinkedList&lt;Integer&gt;();
  
      Integer nextNum = null;
  
      for (int counter = 0; counter &lt; 25; counter ++)
      {
          nextNum = new Integer((int)(Math.random() * 100));
          numList.add(nextNum);
      }
      //output random number LinkedList unsorted
      System.out.printf("Unsorted -- \n" + "Here are the numbers: \n" + numList);
      System.out.println();
      System.out.println();
  
      //Sort LinkedList
      Collections.sort(numList);
      System.out.printf("Sorted -- \n" + "Here are the numbers: \n" + numList);
      System.out.println();
  
      //Output sorted list sum and average
      ListIterator&lt;Integer&gt; iterator = numList.listIterator();
      while (iterator.hasNext())
          count += ((Integer) iterator.next()).intValue();
  
      System.out.printf("The sum of the numbers is %d and the average is %.2f ", count, (double) count / numList.size());
      System.out.println();
  
      ListIterator &lt;Integer&gt; iterator2 = numList.listIterator();
      int listElement = 0;
  
      while(iterator2.hasNext())
      {
          listElement = (Integer)iterator2.next();
          if (listElement %2 == 1)
          {
              iterator2.remove();
          }
      }
  
      ListIterator&lt;Integer&gt; iterator3 = numList.listIterator();
      while (iterator3.hasNext())
          listElement += ((Integer) iterator3.next()).intValue();
  
      System.out.println();
      System.out.printf("With the odd numbers removed -- \n" + "Here are the numbers: \n" + numList);
      System.out.println();
      System.out.printf("The sum of the numbers is %d and the average is %.2f ", listElement, (double) listElement / numList.size());
      }
  
  
  }
  </code></pre>