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