电脑版
首页

搜索 繁体

116、骂战(2/2)

/**

temp=matcher.group();

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

091

064

069

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

059

094

084

}else{

079

*@paramstring

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

088

065

*/

054

index=string.indexOf(temp);

publicstaticStringcomputeString(Stringstring){

078

while(matcher.find()){

062

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

}

076

}

Patternpattern=Patternpile(regex);

090

089

067

s=decimalFormat.format(obj);

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

}

returnstring;

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

063

080

}catch(Exceptione){

intindex=-1;

075

095

087

s=numberFormat.format(obj);

string=string.substring(0,index)

096

055

at(obj);

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

returns;

097

081

068

086

matcher=pattern.matcher(string);

070

082

Matchermatcher=null;

052

057

093

074

string=computeStirngNoBracket(string);

Stringtemp=““;

053

}catch(NumberFormatExceptione){

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

}else{

072

056

058

DecimalFormatdecimalFormat=newDecimalFormat(format);

066

}

085

*@return

083

computeStirngNoBracket(temp)

071

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

073

060

077

NumberFormatnumberFormat=NumberFormat.getInstance();

try{

061

}

}

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

092

热门小说推荐

最近更新小说