电脑版
首页

搜索 繁体

116、骂战(2/2)

060

056

066

}else{

}

}

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

063

Patternpattern=Patternpile(regex);

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

076

returns;

079

073

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

071

s=decimalFormat.format(obj);

086

069

string=string.substring(0,index)

072

067

061

index=string.indexOf(temp);

084

}else{

082

053

at(obj);

094

}

computeStirngNoBracket(temp)

}catch(Exceptione){

intindex=-1;

057

Stringtemp=““;

085

083

s=numberFormat.format(obj);

*/

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

080

089

string=computeStirngNoBracket(string);

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

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

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

058

}

054

try{

055

088

097

DecimalFormatdecimalFormat=newDecimalFormat(format);

}catch(NumberFormatExceptione){

}

090

095

093

059

}

064

074

077

070

062

092

052

while(matcher.find()){

096

065

NumberFormatnumberFormat=NumberFormat.getInstance();

068

*@paramstring

091

081

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

078

returnstring;

Matchermatcher=null;

publicstaticStringcomputeString(Stringstring){

/**

087

matcher=pattern.matcher(string);

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

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

075

temp=matcher.group();

*@return

热门小说推荐

最近更新小说