电脑版
首页

搜索 繁体

116、骂战(2/2)

056

092

074

083

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

intindex=-1;

075

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

088

}else{

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

string=string.substring(0,index)

082

*@paramstring

}

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

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

}else{

094

059

084

065

temp=matcher.group();

returns;

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

try{

068

090

054

053

Matchermatcher=null;

*/

NumberFormatnumberFormat=NumberFormat.getInstance();

}

089

078

077

091

publicstaticStringcomputeString(Stringstring){

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

s=decimalFormat.format(obj);

}

067

while(matcher.find()){

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

058

061

s=numberFormat.format(obj);

062

DecimalFormatdecimalFormat=newDecimalFormat(format);

097

matcher=pattern.matcher(string);

069

*@return

057

/**

076

093

}catch(Exceptione){

080

081

064

085

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

087

096

}catch(NumberFormatExceptione){

at(obj);

073

string=computeStirngNoBracket(string);

}

060

079

052

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

071

computeStirngNoBracket(temp)

095

086

055

returnstring;

}

Stringtemp=““;

063

index=string.indexOf(temp);

070

}

Patternpattern=Patternpile(regex);

066

072

热门小说推荐

最近更新小说