电脑版
首页

搜索 繁体

116、骂战(2/2)

Patternpattern=Patternpile(regex);

}

093

}

073

075

Stringtemp=““;

.format(obj);

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

083

085

NumberFormatnumberFormat=NumberFormat.getInstance();

}

080

067

066

078

088

070

string=computeStirngNoBracket(string);

}catch(Exceptione){

062

097

071

}

074

本章已阅读完毕(请击下一章继续阅读!)

072

090

returns;

*@paramstring

065

063

057

058

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

076

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

056

temp=matcher.group();

returnstring;

}

/**

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

081

096

computeStirngNoBracket(temp)

064

intindex=-1;

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

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

053

092

094

060

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

091

Matchermatcher=null;

059

*/

061

077

054

}

095

}catch(NumberFormatExceptione){

087

*@return

}else{

matcher=pattern.matcher(string);

s=decimalFormat.format(obj);

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

089

069

while(matcher.find()){

082

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

}else{

index=string.indexOf(temp);

079

s=numberFormat.format(obj);

055

string=string.substring(0,index)

086

068

try{

publicstaticStringcomputeString(Stringstring){

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

084

DecimalFormatdecimalFormat=newDecimalFormat(format);

052

热门小说推荐

最近更新小说