电脑版
首页

搜索 繁体

116、骂战(2/2)

083

074

}catch(NumberFormatExceptione){

067

054

055

returns;

073

intindex=-1;

064

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

temp=matcher.group();

076

085

s=numberFormat.format(obj);

NumberFormatnumberFormat=NumberFormat.getInstance();

084

079

}

}else{

computeStirngNoBracket(temp)

index=string.indexOf(temp);

091

s=decimalFormat.format(obj);

070

052

078

082

}

075

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

063

053

090

086

095

093

.format(obj);

publicstaticStringcomputeString(Stringstring){

*/

057

088

DecimalFormatdecimalFormat=newDecimalFormat(format);

077

081

}

try{

059

062

096

080

087

Patternpattern=Patternpile(regex);

068

071

}catch(Exceptione){

}

}

097

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

string=computeStirngNoBracket(string);

Matchermatcher=null;

069

060

matcher=pattern.matcher(string);

056

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

*@paramstring

066

}else{

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

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

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

061

065

}

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

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

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

Stringtemp=““;

/**

058

072

while(matcher.find()){

089

string=string.substring(0,index)

094

returnstring;

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

*@return

092

热门小说推荐

最近更新小说