Completely stumped on a multiple loop Java program
<p>The following is NOT a homework problem, it's just a set of problems that I've been working through for practice and I was wondering if anybody else could figure it out:</p>

<p><a href="http://codingbat.com/prob/p159339" rel="nofollow">http://codingbat.com/prob/p159339</a></p>

<p>Return an array that contains exactly the same numbers as the given array, but rearranged so that every 3 is immediately followed by a 4. Do not move the 3's, but every other number may move. The array contains the same number of 3's and 4's, every 3 has a number after it that is not a 3 or 4, and a 3 appears in the array before any 4. </p>

<p>*SOLVED - here is my working code:</p>

<pre><code>    public int[] fix34(int...nums) 
{
    int[] returnArray = new int[nums.length];

    //ASSIGN ARRAY
    //We know that all 3's can't be moved, and after every 3 there
    //will automatically be a 4

    for(int i = 0; i&lt;nums.length; i++)
    {
        if(nums[i] == 3)
        {
           returnArray[i] = 3;
           returnArray[i+1] = 4;
        }
    }

    //REBUILD ARRAY - UNMOVED INDEXES
    //If a value was not moved/affected by the above, it will get placed into the array
    //in the same position

    for (int i = 0; i &lt; nums.length; i++)
    {
        if (returnArray[i] != 3 &amp;&amp; returnArray[i] != 4 &amp;&amp; nums[i] != 3 &amp;&amp; nums[i] != 4)
        {
            returnArray[i] = nums[i];
        }
    }       

    //REBUILD ARRAY - MOVED INDEXES
    //changed values = 0 in returnArray, as a result, any time we hit a 0 we
    //can simply assign the value that was in the 4's place in the nums array

    OuterLoop: for (int i = 0; i &lt; nums.length; i++)
    {
        if (returnArray[i] == 0)
        {
            for (int n = 0; n &lt; returnArray.length; n++)
            {
                if (returnArray[n] == 4)
                {
                    returnArray[i] = nums[n];
                    continue OuterLoop;
                }
            }
        }
    }

    return returnArray;
}
</code></pre>
