title: Rearrange int array so that all the negative numbers come before the positivite numbers
body: <p>I am trying to write a method which takes an array of <code>int</code>s and then rearranges the numbers in the array so that the negative numbers come first. The array does not need to be sorted in any way. The only requirement is that the solution has to be linear and it does not use an extra array.</p>
  
  <p>Input:</p>
  
  <pre><code>{1, -5, 6, -4, 8, 9, 4, -2}
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>{-5, -2, -4, 8, 9, 1, 4, 6}
  </code></pre>
  
  <p>Now as a noob in Java and programming in general I am not 100% sure on what is considered a linear solution, but my guess is that it has to be a solution that does not use a loop within a loop.</p>
  
  <p>I currently have an awful solution that I know doesn't work (and I also understand why) but I can't seem to think of any other solution. This task would be easy if I were allowed to use a loop within a loop or an additional array but I am not allowed to.</p>
  
  <p>My code:</p>
  
  <pre><code>public static void separateArray(int[] numbers) {
      int i = 0;
      int j = numbers.length-1;
      while(i&lt;j){
  
          if(numbers[i] &gt; 0){
              int temp;
              temp = numbers[j];
              numbers[j] = numbers[i];
              numbers[i] = temp;
              System.out.println(Arrays.toString(numbers));
          }
  
          i++;
          j--;
      }
  }
  </code></pre>