//JDK自带的类可以实现调用JS的功能,可以实现执行字符串中的运算公式的功能。
static ScriptEngine jse = new ScriptEngineManager().getEngineByName("JavaScript");
public static void main(String[] args) {
String strs = "1+1*2+(10-(2*(5-3)*(2-1))-4)+10/(5-0)";
try {
System.out.println(jse.eval(strs));
} catch (Exception t) {
}
}
JDK自带的类可以实现调用JS的功能,可以实现执行字符串中的运算公式的功能。
于 2023-08-25 10:08:42 首次发布