谢谢朋友,我也知道temp.equals("yes")是可以的,但我那样写为什么就不行呢?
比如
   temp="yes";
   if(temp=="yes")
就能成立呢?

解决方案 »

  1.   

    String 的比较是用方法equals解决.temp="yes"是定义当然可以,if(temp=="yes")是比较就不可以了
      

  2.   

    to mtou() :   temp="yes";
       if(temp=="yes")
    是能正确输出结果的,就是说是能比较的,否则怎么会有成立呢?
    我是java新手,请多指教
      

  3.   

    控制台上能看到temp的输出"yes",怎么看到的
      

  4.   

    你用temp.equals可以的到结果吗?那你可以看看你的String temp的长度,看里面是不是有空格所以
    temp="yes"不行
      

  5.   

    用temp.equals是可以得到结果
    System.out.println(temp.getBytes().length );
    得到的结果是3