电脑版
首页

搜索 繁体

116、骂战(2/2)

}

*@return

097

064

072

078

092

080

publicstaticStringcomputeString(Stringstring){

061

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

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

returnstring;

079

088

DecimalFormatdecimalFormat=newDecimalFormat(format);

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

}

067

053

056

068

while(matcher.find()){

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

065

094

076

try{

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

NumberFormatnumberFormat=NumberFormat.getInstance();

intindex=-1;

066

085

Patternpattern=Patternpile(regex);

062

074

058

087

070

}else{

082

060

}catch(NumberFormatExceptione){

string=string.substring(0,index)

091

index=string.indexOf(temp);

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

093

}

/**

075

*/

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

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

temp=matcher.group();

095

086

computeStirngNoBracket(temp)

059

089

}

057

s=numberFormat.format(obj);

090

077

063

returns;

083

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

}

071

}catch(Exceptione){

.format(obj);

069

096

084

081

055

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

string=computeStirngNoBracket(string);

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

Matchermatcher=null;

054

052

Stringtemp=““;

073

s=decimalFormat.format(obj);

*@paramstring

}

}else{

matcher=pattern.matcher(string);

热门小说推荐

最近更新小说