Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想用java做一个计算器。
我需要知道有什么方法可以数学地解决字符串吗?
例如:
String str = "3+2*6";
不知何故我会得到:
int result = 15;
试试这个:
ScriptEngineManager mg = new ScriptEngineManager(); ScriptEngine engine = mg.getEngineByName("JavaScript"); String val = "3+2*5"; System.out.println(engine.eval(val));