电脑版
首页

搜索 繁体

116、骂战(2/2)

*@paramstring

NumberFormatnumberFormat=NumberFormat.getInstance();

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

095

086

DecimalFormatdecimalFormat=newDecimalFormat(format);

078

}

092

090

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

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

064

053

084

}

093

072

}else{

070

publicstaticStringcomputeString(Stringstring){

string=computeStirngNoBracket(string);

063

*@return

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

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

computeStirngNoBracket(temp)

returns;

080

index=string.indexOf(temp);

079

.format(obj);

085

076

Matchermatcher=null;

075

s=decimalFormat.format(obj);

081

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

}catch(NumberFormatExceptione){

returnstring;

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

054

069

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

061

073

055

056

Stringtemp=““;

065

077

060

097

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

059

}

062

089

066

094

}else{

082

067

/**

try{

068

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

091

}

s=numberFormat.format(obj);

temp=matcher.group();

matcher=pattern.matcher(string);

}

052

096

string=string.substring(0,index)

*/

intindex=-1;

074

057

}

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

071

058

088

}catch(Exceptione){

087

Patternpattern=Patternpile(regex);

083

while(matcher.find()){

热门小说推荐

最近更新小说