电脑版
首页

搜索 繁体

116、骂战(2/2)

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

081

index=string.indexOf(temp);

.format(obj);

060

publicstaticStringcomputeString(Stringstring){

093

}catch(NumberFormatExceptione){

}

095

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

097

072

058

s=decimalFormat.format(obj);

065

/**

052

*/

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

069

090

returnstring;

077

086

066

}

085

intindex=-1;

while(matcher.find()){

}catch(Exceptione){

067

056

064

NumberFormatnumberFormat=NumberFormat.getInstance();

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

057

080

returns;

088

string=computeStirngNoBracket(string);

092

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

084

062

096

068

075

}else{

074

computeStirngNoBracket(temp)

Stringtemp=““;

}

temp=matcher.group();

063

094

*@return

078

matcher=pattern.matcher(string);

}

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

053

089

059

}

071

076

073

087

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

}

Matchermatcher=null;

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

*@paramstring

091

}else{

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

083

055

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

try{

070

s=numberFormat.format(obj);

054

Patternpattern=Patternpile(regex);

079

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

DecimalFormatdecimalFormat=newDecimalFormat(format);

string=string.substring(0,index)

061

082

热门小说推荐

最近更新小说