电脑版
首页

搜索 繁体

116、骂战(2/2)

068

//循环计算所有括号里的表达式

056

057

while(matcher.find()){

085

084

temp=matcher.group();

try{

087

returnstring;

at(obj);

066

Stringregex=“\\([\\d\\.\\ \\-\\*/] \\)“;//提取括号表达式

091

061

092

NumberFormatnumberFormat=NumberFormat.getInstance();

s=numberFormat.format(obj);

}

058

065

}else{

062

index=string.indexOf(temp);

publicstaticStringcomputeString(Stringstring){

053

*计算字符串四则运算表达式

070

/**

082

while(pattern.matcher(string).find()){

059

}catch(Exceptione){

computeStirngNoBracket(temp)

}

081

if(!Pattern.matches(regexCheck,string))

Matchermatcher=null;

094

080

076

060

074

string.substring(index temp.length());

}

*@return

064

DecimalFormatdecimalFormat=newDecimalFormat(format);

returne.getMessage();(未完待续。)

returns;

071

//最后计算总的表达式结果

095

096

}

089

}

097

StringregexCheck=“[\\(\\)\\d\\ \\-\\*/\\.]*“;//是否是合法的表达式

075

072

063

086

083

077

Patternpattern=Patternpile(regex);

}else{

090

079

}catch(NumberFormatExceptione){

055

string=computeStirngNoBracket(string);

}

073

matcher=pattern.matcher(string);

intindex=-1;

string=string.substring(0,index)

Stringtemp=““;

069

067

*@paramstring

s=decimalFormat.format(obj);

054

093

078

*/

088

052

string=string.replaceAll(“\\s“,““);//去除空格

热门小说推荐

最近更新小说