Topic: 新手请教一个字符类型问题~在线等指教

  Print this page

1.新手请教一个字符类型问题~在线等指教 Copy to clipboard
Posted by: 好问先生
Posted on: 2008-09-20 10:08

运算符+为什么会报错?
Calculator s = new Calculator();
      Scanner input= new Scanner (System.in);
      
      System.out.println("请输入第一个数字:");
      s.a=input.nextDouble();
      System.out.println("请输入第二个数字:");
      s.b=input.nextDouble();
      System.out.println("运算符:");
      String c;
      s.c=input.next();
      if (c==+)
      {
        System.out.println(s.add());
      }


未命名.bmp (311.24k)

2.Re:新手请教一个字符类型问题~在线等指教 [Re: 好问先生] Copy to clipboard
Posted by: andy_wang_5
Posted on: 2008-09-20 15:01

"==+" 是什么运算?

是不是
"+".equals( c )

3.Re:新手请教一个字符类型问题~在线等指教 [Re: 好问先生] Copy to clipboard
Posted by: smwyzy
Posted on: 2008-10-10 20:25

为什么是
 if (c==+) 

而不是
 if (c='+') 

4.Re:新手请教一个字符类型问题~在线等指教 [Re: 好问先生] Copy to clipboard
Posted by: ice0819
Posted on: 2008-10-19 11:23

应该是if(c==“+”)

5.Re:新手请教一个字符类型问题~在线等指教 [Re: 好问先生] Copy to clipboard
Posted by: junz04
Posted on: 2008-10-25 20:01

应该是if(c.equals(“+”))

6.Re:新手请教一个字符类型问题~在线等指教 [Re: 好问先生] Copy to clipboard
Posted by: JiafanZhou
Posted on: 2008-11-11 22:23

You can write some JUnit tests to test the correctness of this comparison.
Jiafan


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923