我試圖打印2陣列A和B之間的非交集。但是,我有一個問題如何在不同的B.上打印元素。 這是我的示例代碼:查找2個陣列的不同元素
public class Array {
public static void main(String[] args) {
for (int i = 0; i <= arrA.length - 1; i++) {
arrA[i] = sc.nextInt();
}
for (int i = 0; i <= arrB.length - 1; i++) {
arrB[i] = sc.nextInt();
}
boolean x = true;
int y = 0;
for (int i = 0; i < arrA.length; i++) {
for (int j = 0; j < arrB.length; j++) {
if (arrA[i] == arrB[j]) {
arrTestA[i] = true;
}else y = arrA[i];
}
}
for (int i = 0; i < arrA.length; i++) {
x = x && arrTestA[i];
}
if (x) {
System.out.println("All the elements of A contained in B.");
}else {
System.out.println("There are elements on A different B.");
System.out.println("The elements of A which is not in B = "); //My Problem
}
}
}
的[兩個陣列之間的差異(可能的複製http://stackoverflow.com/questions/13732312 /兩個數組之間的差異) – Berger
謝謝。我認爲這沒有問題。問題是我如何得到「不在B = 4中的A的元素」 –