电脑版
首页

搜索 繁体

116、骂战(2/2)

Matchermatcher=null;

while(matcher.find()){

intindex=-1;

060

DecimalFormatdecimalFormat=newDecimalFormat(format);

}

Stringtemp=““;

087

059

056

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

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

string=computeStirngNoBracket(string);

returns;

076

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

096

093

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

073

publicstaticStringcomputeString(Stringstring){

067

082

092

}

085

052

computeStirngNoBracket(temp)

071

058

064

077

054

066

matcher=pattern.matcher(string);

053

097

095

072

078

081

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

string=string.substring(0,index)

}

069

*/

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

returnstring;

index=string.indexOf(temp);

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

/**

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

063

}else{

Patternpattern=Patternpile(regex);

062

088

*@paramstring

}

055

079

080

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

s=numberFormat.format(obj);

094

}else{

091

temp=matcher.group();

070

057

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

065

075

061

try{

089

090

}catch(NumberFormatExceptione){

NumberFormatnumberFormat=NumberFormat.getInstance();

s=decimalFormat.format(obj);

}

*@return

}catch(Exceptione){

068

084

}

at(obj);

083

086

074

热门小说推荐

最近更新小说