““;
078
intindex=-1;
079
Stringregex=“\\([\\d\\.\\+\\-\\*/]+\\)“;//提取括号表达式
080
string=string.replaceAll(“\\s“,““);//去除空格
081
try{
082
Patternpattern=Pattern.compile(regex);
083
//循环计算所有括号里的表达式
084
while(pattern.matcher(string).find()){
085
matcher=pattern.matcher(string);
086
while(matcher.find()){
087
temp=matcher.group();
088
index=string.indexOf(temp);
089
string=string.substring(0,index)
090
+computeStirngNoBracket(temp)
091
+string.substring(index+temp.length());
092
}
093
}
094
//最后计算总的表达式结果
095
string=computeStirngNoBracket(string);
096
}catch(NumberFormatExceptione){
097
returne.getMessage();
(未完待续。)