title: How to print only the last element of an array?
body: <p>I am trying to print the last element of my array. The code can be seen below: </p>
  
  <pre><code>double [] results = new double[21];
  double t = 9600;
  
  for(int y = 0; y &lt; 21; y++) {
  
      results[y] = t;
      t *= 1.04;
  
      System.out.println(results[results.length - 1]);
  
  }
  </code></pre>
  
  <p>However, when I attempt to run this, I get this result: </p>
  
  <pre><code>0.0 (printed 20 times in a row)
  ...
  21034.782173120842 
  </code></pre>
  
  <p>I do not know why it is printing out 20 zero's, and then the answer I want <code>(21034.78)</code>. I thought that by doing <code>results[results.length - 1]</code>, only the last element of the array would be printed. I have a suspicion that this has to do with the loop, but I do not know why or how to fix it. </p>
  
  <p>Any help or advice would be greatly appreciated. Thank you!</p>