就是一个表达式求值的问题,用DS中的Stack实现,比较经典的就是逆波兰表达式求值,这个还比那个更简单

解决方案 »

  1.   

    那你为什么不直接用double呢
    就不要用String了
    要不你就类型转换
    用不着什么数据结构我想用了型转换可以解决上面的问题
      

  2.   

    http://www.csdn.net/develop/article/15/15095.shtm// Eval.java
    import bsh.Interpreter;public class Eval
    {
    public static void main(String[] args) throws Exception
    {
    Interpreter i = new Interpreter();  // Construct an interpreter
    String s = "16*(9+5)+(8-3)/7";
    // Double d = new Double(i.eval(s).toString());
    // System.out.println("output is: " + d);
    System.out.println("output is: " + i.eval(s));
    }
    }
      

  3.   

    TO: liad() 
    假如表达式为:(A+3)*(B-C)+7+CD 呢??
      

  4.   

    to liad() :
    您的程序在 在main(String[] args) throws Exception语句里去掉throws Exception
    就会出错  Unhandled exception type EvalError.不去可以通过如果在子程序(方法)中写,并加上throws Exception,子程序出错Unhandled exception type Exception,不加的话Unhandled exception type EvalError
    偶必须在子程序里调用,该怎么办?throws 什么的偶没用过,太菜了