import java.util.Arrays;
public class Main {
public static void main(String args[]) {
int[] a=new int[]{1,2,3,4,5,6,7,8,9};
sort(a);
System.out.println(Arrays.toString(a));
}
public static void sort(int[] aa) {
if (aa == null && aa.length == 0) {
return;
}
for (int i = 0, j = 0; i < aa.length; i++) {
if ((aa[i] & 1) != 0) {
int temp = aa[i];
aa[i] = aa[j];
aa[j] = temp;
j++;
}
}
}
}
【Java】将一维数组的奇数置与偶数前面,不考虑变化后顺序
最新推荐文章于 2021-10-27 20:22:30 发布