当前位置: 代码迷 >> Java相关 >> java异或运算符问题 请教下 谢谢
  详细解决方案

java异或运算符问题 请教下 谢谢

热度:112   发布时间:2010-10-02 12:54:03.0
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  

----------------解决方案--------------------------------------------------------
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));
        }
    }



----------------解决方案--------------------------------------------------------
谢谢哈
----------------解决方案--------------------------------------------------------
  相关解决方案