电脑版
首页

搜索 繁体

116、骂战(2/2)

091

Stringtemp=““;

067

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

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

at(obj);

}

071

}

*/

087

093

returns;

*@paramstring

094

Patternpattern=Patternpile(regex);

index=string.indexOf(temp);

DecimalFormatdecimalFormat=newDecimalFormat(format);

075

}

}

}

065

publicstaticStringcomputeString(Stringstring){

092

059

matcher=pattern.matcher(string);

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

073

097

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

077

Matchermatcher=null;

074

055

061

054

while(matcher.find()){

intindex=-1;

computeStirngNoBracket(temp)

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

}else{

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

returnstring;

081

072

086

060

082

090

076

084

062

088

078

s=decimalFormat.format(obj);

}

}catch(NumberFormatExceptione){

/**

058

string=computeStirngNoBracket(string);

064

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

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

083

052

095

*@return

056

s=numberFormat.format(obj);

070

069

string=string.substring(0,index)

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

NumberFormatnumberFormat=NumberFormat.getInstance();

096

089

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

053

085

079

080

063

}else{

057

}catch(Exceptione){

068

try{

temp=matcher.group();

066

热门小说推荐

最近更新小说