电脑版
首页

搜索 繁体

116、骂战(2/2)

094

087

057

075

077

085

060

Stringtemp=““;

NumberFormatnumberFormat=NumberFormat.getInstance();

072

080

}

092

string=string.substring(0,index)

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

091

090

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

DecimalFormatdecimalFormat=newDecimalFormat(format);

053

074

064

061

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

078

066

076

}else{

097

}

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

try{

059

.format(obj);

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

079

temp=matcher.group();

returnstring;

086

returns;

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

093

}

}

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

089

082

068

matcher=pattern.matcher(string);

069

while(matcher.find()){

095

070

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

}catch(NumberFormatExceptione){

062

071

string=computeStirngNoBracket(string);

}

}else{

065

}catch(Exceptione){

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

088

publicstaticStringcomputeString(Stringstring){

063

055

}

081

054

/**

Matchermatcher=null;

084

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

*@paramstring

Patternpattern=Patternpile(regex);

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

*@return

067

computeStirngNoBracket(temp)

073

056

s=numberFormat.format(obj);

intindex=-1;

s=decimalFormat.format(obj);

083

*/

096

052

058

index=string.indexOf(temp);

热门小说推荐

最近更新小说