Java 里调用 JavaScript 功能
- 把字符串读成计算式
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class Main {
public static void main(String[] args) throws ScriptException {
ScriptEngine se = new ScriptEngineManager().getEngineByName("js");
System.out.println(se.eval("12*3+52-32/4+2"));
}
网友评论