import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
String jg = "2+3*5";
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
Object result = null;
try {
result = engine.eval(jg);
} catch (ScriptException e) {
e.printStackTrace();
}
System.out.println("结果:" + rsult));
Java代码利用ScriptEngineManager实现字符串公式灵活计算
最新推荐文章于 2024-07-23 17:41:48 发布