调整数组中数字的顺序,使得所有奇数位于数组的前半部分
public class Test03 { public static void main(String[] args) { int [] a = {1,2,3,4,5,6,7,8,9,10,11,12}; int i,m; m = a.length-1; for(i = 0; i <= m;){ if(a[i]%2 == 0){ a[i] = a[i] + a[m]; a[m] = a[i]- a[m]; a[i] = a[i]-a[m]; m--; }else i++; } for(int j : a){ System.out.print(j+" "); } } }