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