字符串不用分割直接进行加减乘除的操作
- 每天一个无用小技巧!
try {
ScriptEngine javascript = new ScriptEngineManager().getEngineByName("JavaScript");
String string = "1*3-6+8/2";
//这里是强制转换成数据类型
Double double = (Double)javascript .eval(string );
System.out.println(double );
} catch (ScriptException e) {
e.printStackTrace();
}
输出结果:1