java 1.6 表达式计算方法

 

 
import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class Test{ public static void main(String[] args) { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName( " javascript " ); try { Double d = (Double) engine.eval( " 10*5+9-25/2 " ); System.out.println(d); } catch (ScriptException ex) { } } }

你可能感兴趣的:(JavaScript,java)