2019-03-13

Java 里调用 JavaScript 功能

  1. 把字符串读成计算式
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"));
    }

你可能感兴趣的:(2019-03-13)