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