用java解析字符串,并计算结果。如字符串"(1+2/5)*3"当成是数值表达式,进行计算出结果来

用java解析字符串,如字符串"(1+2/5)*3"当成是数值表达式,进行计算出结果来
import java.io.*;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class Main
{
public static void main(String[] args) throws Exception
{
String expr = "(1+2/5)*3";
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
Object result = engine.eval(expr);
System.out.println(result);
}
}

上一篇:TraceView性能分析工具介绍


下一篇:智能家居行业步入死胡同 未来何去何从?