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