title: Swapping corresponding elements in an Array
body: <p>How would I switch corresponding elements in an array (Ex: First with last, Second with one before last) using a loop. I've worked out the code using a loop, but it doesn't give the desired result in Eclipse.</p>
  
  <pre><code>int[] a = {1, 2, 3, 4, 5};
  int k = 0;
  int temp = 0;
  while(k &lt; a.length)
  {
    temp = a[k];
    a[k] = a[a.length - 1 - k];
    a[a.length - 1 - k] = temp;
    k++;
  }
  </code></pre>
  
  <p>Assume that you don't know the values in the array or how long it is. </p>