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)); } }
TO: liad() 假如表达式为:(A+3)*(B-C)+7+CD 呢??
to liad() : 您的程序在 在main(String[] args) throws Exception语句里去掉throws Exception 就会出错 Unhandled exception type EvalError.不去可以通过如果在子程序(方法)中写,并加上throws Exception,子程序出错Unhandled exception type Exception,不加的话Unhandled exception type EvalError 偶必须在子程序里调用,该怎么办?throws 什么的偶没用过,太菜了
就不要用String了
要不你就类型转换
用不着什么数据结构我想用了型转换可以解决上面的问题
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));
}
}
假如表达式为:(A+3)*(B-C)+7+CD 呢??
您的程序在 在main(String[] args) throws Exception语句里去掉throws Exception
就会出错 Unhandled exception type EvalError.不去可以通过如果在子程序(方法)中写,并加上throws Exception,子程序出错Unhandled exception type Exception,不加的话Unhandled exception type EvalError
偶必须在子程序里调用,该怎么办?throws 什么的偶没用过,太菜了