电脑版
首页

搜索 繁体

116、骂战(2/2)

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

094

085

}

063

071

returnstring;

}

061

057

066

temp=matcher.group();

}else{

095

}

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

}catch(Exceptione){

s=numberFormat.format(obj);

publicstaticStringcomputeString(Stringstring){

s=decimalFormat.format(obj);

}catch(NumberFormatExceptione){

059

returns;

}

092

062

074

.format(obj);

054

065

068

index=string.indexOf(temp);

*@paramstring

087

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

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

089

088

intindex=-1;

DecimalFormatdecimalFormat=newDecimalFormat(format);

096

}

055

076

*@return

Matchermatcher=null;

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

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

056

string=string.substring(0,index)

}else{

052

072

073

/**

string=computeStirngNoBracket(string);

053

NumberFormatnumberFormat=NumberFormat.getInstance();

078

try{

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

058

060

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

093

075

*/

079

091

matcher=pattern.matcher(string);

}

computeStirngNoBracket(temp)

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

Patternpattern=Patternpile(regex);

081

097

090

080

082

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

while(matcher.find()){

083

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

070

086

077

069

084

Stringtemp=““;

067

064

热门小说推荐

最近更新小说