/*int[]arr={1,2,5,213,75,42,64,48,21,44,22};
分为3个数组 第一个数组满足全是偶数
第二个数组满足全是3的倍数 第三个数组满足其他*/
public class E{public static void main(String[]args){int[]arr={1,2,5,213,75,42,64,48,21,44,22};int b=0,c=0,d=0;//遍历数组,得到每个数组的长度,bcd.for(int i=0;i<arr.length;i++){if(arr[i]%2==0){b++;}else if(arr[i]%3==0){c++;}else{d++;}}//申明三个数组int[]brr=new int[b];int[]crr=new int[c];int[]drr=new int[d];//给每个数组赋值.for(int i=0,b1=0,c1=0,d1=0;i<arr.length;i++){if(arr[i]%2 == 0){brr[b1]=arr[i];b1++;}else if(arr[i]%3 == 0){crr[c1]=arr[i];c1++;}else{drr[d1]=arr[i];d1++;}}//原来数组for(int i = 0;i<arr.length;i++){System.out.print(arr[i]+" ");}System.out.print("\n");//被分开的数组.for(int i=0;i<brr.length;i++){System.out.print(brr[i]+" ");}System.out.print("\n");for(int i=0;i<crr.length;i++){System.out.print(crr[i]+" ");}System.out.print("\n");for(int i=0;i<drr.length;i++){System.out.print(drr[i]+" ");} }
}//此题注意b1,c1,d1三个变量的改变