mport java.io.*;
class Exp23
{public static void main(String argl[])
  {int n=20, m=5,result;
   char op;
  try { op=(char)(System.in.read()); 
          if (op='+')
              result=n+m;
           else
            {if(op='-')
                 result=n-m;
              else
               {if(op='*')
                   result=n*m;
                 else
                    if(op='/')
                     result=n/m;
                    else
                       System.out.println("operator input error");
                }
              }
         if(op='+' || op='-' || op='*' || op='/')
            System.out.println("result="+result);
    }catch(IOException e)  {System.out.println("in put error");}  
  }
}

解决方案 »

  1.   

    (op = '-') 这样的语句改为 (op == '-')
      

  2.   

    谢谢,解决了
    System.out.println("result="+result);这句也不对吗?
      

  3.   

    楼主看起来是初学者啊,基础类型的等值判运算号是 “==”,赋值运算符才是“=”。System.out.println("result="+result); 这里面的=号,只是个字符串而已,根本不是运算符,谈不上什么错误。
      

  4.   

    是的,我才刚开始学。
    Exp23.java:23: variable result might not have been i
                System.out.println( "result="+result);
    为什么这句话也有问题,该怎么做呢?
                                              ^
      

  5.   

    ==才是判断是否相等=是赋值运算符,返回的就是赋值的结果char类型
      

  6.   


    这个错误的级别高一些,意思是result可能没有赋值,所以不能通过编译,解决方式很简单:就是给它赋与初始值,修改第一行代码,比如:
    int n=20, m=5,result =0;
    int n=20, m=5,result =Integer.MIN_VALUE;