我试图打印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的元素” –