电脑版
首页

搜索 繁体

116、骂战(2/2)

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

081

returnstring;

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

index=string.indexOf(temp);

*@paramstring

090

string=string.substring(0,index)

}

}else{

061

080

067

072

*/

053

058

082

085

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

s=decimalFormat.format(obj);

.format(obj);

096

089

060

093

073

}

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

}

088

056

}catch(NumberFormatExceptione){

Patternpattern=Patternpile(regex);

052

while(matcher.find()){

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

}

068

054

returns;

string=computeStirngNoBracket(string);

DecimalFormatdecimalFormat=newDecimalFormat(format);

}catch(Exceptione){

matcher=pattern.matcher(string);

095

079

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

try{

s=numberFormat.format(obj);

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

083

*@return

}

Matchermatcher=null;

076

091

064

/**

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

}

066

087

092

publicstaticStringcomputeString(Stringstring){

075

055

062

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

086

074

NumberFormatnumberFormat=NumberFormat.getInstance();

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

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

065

078

070

094

}else{

computeStirngNoBracket(temp)

071

temp=matcher.group();

063

057

084

059

077

097

intindex=-1;

Stringtemp=““;

069

热门小说推荐

最近更新小说