我不明白为什么代码不将唯一元素复制到另一个数组。这是我的代码。我虽然==
是复制元素,但我得到了一个错误,所以我改用了=
。
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] B = new int[15];
B[2] = 2;
B[3] = 3;
B[4] = 4;
B[5] = 5;
B[6] = 6;
B[7] = 7;
B[8] = 8;
B[9] = 9;
B[10] = 10;
int[] check = new int[B.length];
for (int i = 0; i < B.length; i++) {
for (int x = 0; x < check.length; x++) {
if (B[i] != check[x]) {
check[x] = B[i];
}
}
}
for (int i = 0; i < check.length; i++) {
System.out.println(check[i]);
}
}