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