异或运算符^

给数组a,求出a中单个的数字

public class YH {

public static void main(String[] args) {
int[] a=new int[] {2,8,1,1,8,3,2};
int r=0;
for(int i=0;i<7;i++) {
r^=a[i];//异或“^” 相同为0,相异为1;例如:0^s=s, s^s=0, a^b^b^a=0;
}
System.out.println(r);

}

}

猜你喜欢

转载自www.cnblogs.com/smailjunk/p/8993233.html