电脑版
首页

搜索 繁体

116、骂战(2/2)

066

}

069

*@return

088

*@paramstring

}else{

052

096

076

067

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

074

}catch(NumberFormatExceptione){

intindex=-1;

075

string=computeStirngNoBracket(string);

}

*/

082

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

059

while(matcher.find()){

}catch(Exceptione){

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

matcher=pattern.matcher(string);

065

091

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

s=numberFormat.format(obj);

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

060

078

DecimalFormatdecimalFormat=newDecimalFormat(format);

063

}

090

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

086

072

Patternpattern=Patternpile(regex);

084

081

returnstring;

056

097

}

string=string.substring(0,index)

068

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

085

080

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

062

095

NumberFormatnumberFormat=NumberFormat.getInstance();

temp=matcher.group();

089

returns;

071

053

at(obj);

094

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

}

s=decimalFormat.format(obj);

}

Stringtemp=““;

058

093

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

Matchermatcher=null;

index=string.indexOf(temp);

055

061

070

087

073

083

092

/**

computeStirngNoBracket(temp)

064

079

publicstaticStringcomputeString(Stringstring){

try{

057

}else{

077

054

热门小说推荐

最近更新小说