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