我有一个字符串,其中包含和号,空格和som'+'和'-'字符。我现在想知道如何求和减去它们! 喜欢 字符串s =“ 25 + 14-13 + 225-16”; 我想输出为= 235
答案 0 :(得分:0)
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
public class Test {
public static void main(String[] args) throws ScriptException {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String foo = "40+2";
System.out.println(engine.eval(foo));
}
}