繁体
StringregexCheck=“[\\(\\)\\d\\ \\-\\*/\\.]*“;//是否是合法的表达式
065
084
071
at(obj);
087
}
returnstring;
081
056
computeStirngNoBracket(temp)
}catch(NumberFormatExceptione){
*计算字符串四则运算表达式
intindex=-1;
074
093
094
078
077
060
}
062
}
067
096
Patternpattern=Patternpile(regex);
string=string.replaceAll(“\\s“,““);//去除空格
string.substring(index temp.length());
069
073
}else{
070
089
079
053
while(matcher.find()){
055
Stringtemp=““;
068
index=string.indexOf(temp);
064
058
086
091
//最后计算总的表达式结果
//循环计算所有括号里的表达式
076
092
}catch(Exceptione){
097
matcher=pattern.matcher(string);
returns;
Matchermatcher=null;
*@paramstring
*/
string=computeStirngNoBracket(string);
*@return
066
072
083
090
}
}
Stringregex=“\\([\\d\\.\\ \\-\\*/] \\)“;//提取括号表达式
080
061
088
095
if(!Pattern.matches(regexCheck,string))
while(pattern.matcher(string).find()){
temp=matcher.group();
054
075
returne.getMessage();(未完待续。)
052
publicstaticStringcomputeString(Stringstring){
059
082
057
}
string=string.substring(0,index)
}else{
DecimalFormatdecimalFormat=newDecimalFormat(format);
s=numberFormat.format(obj);
063
try{
s=decimalFormat.format(obj);
NumberFormatnumberFormat=NumberFormat.getInstance();
/**
085