java异或运算符问题 请教下 谢谢
为什么在这个程序的异或运算符用不了啊 请教大伙帮忙下 谢谢
import java.util.*;
public class YiHuo{
public static void main(String args[]){
Scanner reader=new Scanner(System.in);
while(reader.hasNextInt()){
int x=reader.NextInt();
int y=reader.nextInt();
System.out.print("C1="+ x^y);
}
}
}
----------------解决方案--------------------------------------------------------
java严格区分大小写
nextInt()的n要小写
其次String无法和int异或
"C1="+x^y;
优先执行"C1="+x,返回依旧是String类型,而后面y是int,两者不能异或。
程序代码:
public static void main(String args[]) {
Scanner reader = new Scanner(System.in);
while (reader.hasNextInt()) {
int x = reader.nextInt();
int y = reader.nextInt();
System.out.print("C1=" + (x ^ y));
}
}
Scanner reader = new Scanner(System.in);
while (reader.hasNextInt()) {
int x = reader.nextInt();
int y = reader.nextInt();
System.out.print("C1=" + (x ^ y));
}
}
----------------解决方案--------------------------------------------------------
谢谢哈
----------------解决方案--------------------------------------------------------