import java.util.Arrays;
public class pra
{
public static int[] pra(int[] nums)
{
int begin = 0;
int end = nums.length - 1;
while (begin < end)
{
while (begin < end && nums[begin] % 2 == 0)
{
begin++;
}
while (begin < end && nums[end] % 2 != 0)
{
end--;
}
swap(nums, begin, end);
}
return nums;
}
public static void swap(int[] nums,int begin,int end)
{
int t = nums[begin];
nums[begin] = nums[end];
nums[end] = t;
}
public static void main(String[] args)
{
System.out.println(Arrays.toString(pra(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9})));
}
}//数组数值是不能够整体输出的,而借助Arrays.toString就节省了上面的循环步骤。
运行结果