电脑版
首页

搜索 繁体

116、骂战(2/2)

}

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

NumberFormatnumberFormat=NumberFormat.getInstance();

while(matcher.find()){

076

s=numberFormat.format(obj);

058

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

}

053

081

string=string.substring(0,index)

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

060

059

066

087

string=computeStirngNoBracket(string);

091

computeStirngNoBracket(temp)

079

}

Stringtemp=““;

067

077

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

}else{

*/

publicstaticStringcomputeString(Stringstring){

DecimalFormatdecimalFormat=newDecimalFormat(format);

}else{

*@return

078

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

088

084

069

071

083

}catch(Exceptione){

073

061

}

093

090

085

074

096

}

056

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

returns;

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

try{

094

070

062

}

072

092

052

097

temp=matcher.group();

returnstring;

intindex=-1;

matcher=pattern.matcher(string);

Matchermatcher=null;

*@paramstring

055

}catch(NumberFormatExceptione){

080

.format(obj);

075

065

Patternpattern=Patternpile(regex);

064

095

082

index=string.indexOf(temp);

054

/**

068

s=decimalFormat.format(obj);

086

063

057

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

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

089

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

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

热门小说推荐

最近更新小说