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