Java 里調(diào)用 JavaScript 功能
- 把字符串讀成計(jì)算式
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"));
}