title: Swapping first array element with last, second with second last and so on
body: <p>I have an array, where I have to swap the first value with last, second with second last, and so on.</p>
  <p>I tried doing it like in the code below, but it only works halfway, replacing the other half with zeros. Could somebody explain what is wrong here, please?</p>
  <pre class="lang-java prettyprint-override"><code>for (i = 0; i &lt; arr.length; i++) {
      temp = arr[i];
      arr[i] = arr[arr.length - 1 - i];
      arr[arr.length - 1 - i] = temp;
  }
  </code></pre>