title: How can I move all even numbers to front in an array?
body: <p>Following is the problem-</p>
  
  <p>Given an array of integers as input, return an array that contains the same numbers as that in the input array, but rearranged so that all the even numbers are in front and the odds numbers are at the back. Note that the order of the even numbers and odd numbers should be maintained i.e. if an even number <code>n1</code> that appears before an even number <code>n2</code> in the input, then in the output array <code>n1</code> should appear before <code>n2</code>. The same is true for odd numbers. Also note that in this problem you should not create any new array.</p>
  
  <p>What is done so far is as follows but I am unable to get the expected output.</p>
  
  <pre><code>public class MoveEvenToFront {
  
      static int[] testcase1 = {3, 5, 4, 6, 8, 9, 7, 10};
  
      public static void main(String[] args) {
  
          MoveEvenToFront testInstance = new MoveEvenToFront();
          int[] result = testInstance.moveEvenToFront(testcase1);
          System.out.print("{");
  
          for (int i = 0; i &lt; result.length; i++) {
              if (i &gt; 0) {
                  System.out.print(",");
              }
              System.out.print(result[i]);
          }
          System.out.print("}");
      }
  
      public int[] moveEvenToFront(int[] arr) {
          int temp = 0;
  
          for (int i = 1; i &lt; arr.length; i++) {
              if (arr[i - 1] % 2 != 0) {
                  temp = arr[i - 1];
                  arr[i - 1] = arr[i];
                  arr[i] = temp;
              }
          }
          return arr;
      }
  }
  </code></pre>
  
  <p>The expected output for testcase <code>{1,2,3,4,5,6,7,8,10,12}</code> is <code>{2,4,6,8,10,12,1,3,5,7}</code>.</p>