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