title: Java reverse array method
body: <p>I'm trying to create a method that takes in an array and then returns that array in reverse. The code I wrote returns the array in reverse, but, the first two values are now 0. Anyone know what I did wrong?</p>
  
  <pre><code>public static int[] reverse(int[] x)
  {     
      int []d = new int[x.length];
  
      for (int i = 0; i &lt; x.length/2; i++)  // for loop, that checks each array slot
      {
          d[i] = x[i];
          x[i] = x[x.length-1-i];  // creates a new array that is in reverse order of the original
          x[x.length-1-i] = d[i];
      }
      return d;      // returns the new reversed array  
  }
  </code></pre>