2020/10/6
一
import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class ExpressionCalculate { public static void main(String[] args) { String n=new String(); n= "6*5*(5+6)"; ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("nashorn"); String expression = n; try { String result = String.valueOf(scriptEngine.eval(expression)); System.out.println(result); } catch (ScriptException e) { e.printStackTrace(); } } }
使用该包可以实现四则运算
二.对括号的压栈
三.javaweb