public class Demo{
public static void main(String
[] args
){
int[] array
= {1,0,1};
Demo demo
= new Demo();
System
.out
.print(demo
.getSingleNum(array
));
}
public int getSingleNum(int[] array
){
int num
= 0;
for(int i
= 0 ; i
< array
.length
; i
++){
num
^= array
[i
];
}
return num
;
}
}
但是又有一个新的问题,假如为字符嘞,于是又开始新的征程。先来个小小的测试案例:
public class Test {
static int count
= 0;
public static void main(String
[] args
) {
System
.out
.println('a'^'b');
}
}
输出结果为:3 在计算机底层对字符进行^操作运算,会自动转换成ASCII值进行运算a 值97 b为98 a 0110 0001 b 0110 0010 结果: 0000 0011 为 3