如何将逻辑运算字符串转化为逻辑运算进行运算?

String str2 = “N1 = 23;”;
str2 += “100-N1^2”;
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName(“js”);
Object result = null;
try {
result = engine.eval(str2);
} catch (ScriptException e) {
e.printStackTrace();
}

System.out.println("结果类型:" + result.getClass().getName() + ",计算结果:" + result);

你可能感兴趣的:(如何将逻辑运算字符串转化为逻辑运算进行运算?)