电脑版
首页

搜索 繁体

116、骂战(2/2)

publicstaticStringcomputeString(Stringstring){

072

string=string.substring(0,index)

094

062

NumberFormatnumberFormat=NumberFormat.getInstance();

}

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

058

059

Matchermatcher=null;

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

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

060

computeStirngNoBracket(temp)

067

085

064

057

069

Patternpattern=Patternpile(regex);

070

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

Stringtemp=““;

056

063

returns;

}

090

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

}catch(NumberFormatExceptione){

}

082

}else{

while(matcher.find()){

s=decimalFormat.format(obj);

temp=matcher.group();

078

075

066

string=computeStirngNoBracket(string);

077

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

091

053

*/

returnstring;

071

068

}catch(Exceptione){

095

089

074

*@return

055

084

matcher=pattern.matcher(string);

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

092

086

096

}else{

054

052

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

065

073

080

at(obj);

*@paramstring

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

s=numberFormat.format(obj);

093

087

097

081

}

/**

061

intindex=-1;

index=string.indexOf(temp);

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

083

076

079

088

try{

}

}

DecimalFormatdecimalFormat=newDecimalFormat(format);

热门小说推荐

最近更新小说