电脑版
首页

搜索 繁体

116、骂战(2/2)

}

055

082

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

}

074

intindex=-1;

s=numberFormat.format(obj);

}catch(NumberFormatExceptione){

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

059

073

095

071

093

094

}catch(Exceptione){

064

063

072

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

057

Stringtemp=““;

*/

091

079

081

}else{

077

Matchermatcher=null;

.format(obj);

076

index=string.indexOf(temp);

066

085

075

publicstaticStringcomputeString(Stringstring){

}

080

088

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

097

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

matcher=pattern.matcher(string);

087

062

s=decimalFormat.format(obj);

092

string=computeStirngNoBracket(string);

本章已阅读完毕(请击下一章继续阅读!)

*@return

returns;

Patternpattern=Patternpile(regex);

061

}else{

067

086

069

/**

083

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

while(matcher.find()){

053

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

}

*@paramstring

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

058

}

temp=matcher.group();

096

089

try{

068

070

052

DecimalFormatdecimalFormat=newDecimalFormat(format);

065

NumberFormatnumberFormat=NumberFormat.getInstance();

090

computeStirngNoBracket(temp)

078

string=string.substring(0,index)

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

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

054

084

returnstring;

}

060

056

热门小说推荐

最近更新小说