IntegerUtilities { public static int[] permutate(int[] numberArray) { if (isEven(numberArray.length) && numberArray.length > 2) { int[] permutatedIndices = new int[numberArray.length]; int indexMiddle = numberArray.length / 2; for (int index = 0; index < indexMiddle; index++) { permutatedIndices[2 * index] = numberArray[indexMiddle - 1 - index]; permutatedIndices[2 * index + 1] = numberArray[numberArray.length - 1 - index]; } return permutatedIndices; } if (numberArray.length == 3) { return new int[]{numberArray[2], numberArray[0], numberArray[1]}; } return revert(numberArray); }  static int[] permutate(int[] numberArray);  }
@Test public void testPermutateArray() throws Exception { Assert.assertTrue(Arrays.equals(new int[] { 2, 1 }, IntegerUtilities.permutate(new int[]{1, 2}))); Assert.assertTrue(Arrays.equals(new int[] { 2, 4, 1, 3 }, IntegerUtilities.permutate(new int[] { 1, 2, 3, 4 }))); Assert.assertTrue(Arrays.equals(new int[] { 3, 6, 2, 5, 1, 4 }, IntegerUtilities.permutate(new int[] { 1, 2, 3, 4, 5, 6 }))); }