public class CopyArray {
public static void main(String[] args) {
copyNoSort();
System.out.println("sort: ");
copySort();
}
// 循环进行m*n次
public static void copyNoSort() {
int[] arrayA = new int[] { 11, 1, 2, 13, 4, 5, 6, 7, 8, 9 };
int[] arrayB = new int[] { 2, 4, 6, 8 };
int[] arrayC = new int[arrayA.length - arrayB.length];
int t = 0;
for (int i = 0; i < arrayA.length; i++) {
boolean isHave = true;
for (int k = 0; k < arrayB.length; k++) {
if (arrayA[i] == arrayB[k]) {
isHave = false;
}
}
if (isHave) {
arrayC[t] = arrayA[i];
t++;
}
}
for (int i = 0; i < arrayC.length; i++) {
System.out.print(arrayC[i] + ", ");
}
}
public static void copySort() {
int[] arrayA = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13 };
int[] arrayB = new int[] { 2, 4, 6, 8 };
int[] arrayC = new int[arrayA.length - arrayB.length];
int k = 0;
int t = 0;
for (int i = 0; i < arrayA.length; i++) {
if (k < arrayB.length) {
if (arrayA[i] < arrayB[k]) {
arrayC[t] = arrayA[i];
t++;
} else {
k++;
}
} else {
arrayC[t] = arrayA[i];
t++;
}
}
for (int i = 0; i < arrayC.length; i++) {
System.out.print(arrayC[i] + ", ");
}
}
}
|