title: ArrayList in Java that lists square numbers - Homework
body: <p>I think I have most of the code figured out, there is just one part that is giving me grief. When I use printList(list) it prints out 1, 2, 3,... up to 9 when it is supposed to be printing the squares of these numbers. If I print out the createSquaresList(10) it is correctly printed. Any help is appreciated :-).</p>
  
  <pre><code>import java.util.*;
  
  public class Lab8a
  {
      public static void main(String args[])
      {
          ArrayList&lt;Double&gt; list = createSquaresList(10);
          printList(list);
          removeElement(list, 4);
          printList(list);
          swapElements(list, 2, 6);
          printList(list);
          double max = getMaxValue(list);
          double ave = getAverage(list);
          System.out.println("Max Value = " + max);
          System.out.println("Average = " + ave);
          int idx1 = linearSearch(list, 4);
          int idx2 = linearSearch(list, 75);
          System.out.println("idx 1 = " + idx1);
          System.out.println("idx 2 = " + idx2);
      }
  
      public static ArrayList&lt;Double&gt; createSquaresList(int n)
      {
          ArrayList&lt;Double&gt; squares= new ArrayList&lt;&gt;();
          double s = 0.0;
          for (double i = 0.0; i &lt;= n-1; i++)
          {
              s = i*i;
              squares.add(s);
          }
          return squares;
      }
  
      public static double getMaxValue(ArrayList&lt;Double&gt; list)
      {
          double largest = list.get(0);
          for (int i = 1; i &lt; list.size(); i++)
          {
              if (list.get(i) &gt; largest)
              {
                  largest = list.get(i);
              }
          }
          return largest;
      }
  
      public static double getAverage(ArrayList&lt;Double&gt; list)
      {
            double avg = 0.0;
            double sum = 0.0;
            for (int i =0; i &lt; list.size(); i++)
            {
                sum += list.get(i);
            }
            avg = sum / list.size();
            return avg;
      }
  
      public static void removeElement(ArrayList&lt;Double&gt; list, double index)
      {
          double temp = 0.0;
          int lastPos = list.size() - 1;
          double last = list.get(lastPos);
          index = temp;
          temp = last;
          last = index;
          list.remove(lastPos);
      }
  
      public static void swapElements(ArrayList&lt;Double&gt; list, int a, int b)
      {
          int temp = 0;
          a = temp;
          temp = b;
          b = a;
  
      }
  
      public static int linearSearch(ArrayList&lt;Double&gt; list, double val)
      {
          int pos = 0;
          boolean found = false;
          while (pos &lt; list.size() &amp;&amp; !found)
          {
              if (list.get(pos) == val)
              {
                  found = true;
              }
              else
              {
                  pos++;
              }
          }
          if (found)
          {
              return pos;
          }
          else
          {
              return -1;
          }
      }
  
      public static void printList(ArrayList&lt;Double&gt; list)
      {
          for(int i = 0; i &lt; list.size(); i++)
          {
              System.out.print(i);
              if(i &lt; list.size()-1)
              {
                  System.out.print(", ");
              }
          }
          System.out.println("");
      }
  }
  </code></pre>