电脑版
首页

搜索 繁体

116、骂战(2/2)

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

095

Stringtemp=““;

068

Patternpattern=Patternpile(regex);

intindex=-1;

056

081

/**

055

*/

092

097

returnstring;

094

}catch(Exceptione){

082

084

074

078

075

054

062

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

while(matcher.find()){

064

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

076

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

DecimalFormatdecimalFormat=newDecimalFormat(format);

}

096

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

}

}

088

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

returns;

059

058

NumberFormatnumberFormat=NumberFormat.getInstance();

string=string.substring(0,index)

073

temp=matcher.group();

087

computeStirngNoBracket(temp)

090

}catch(NumberFormatExceptione){

086

060

057

065

072

052

080

Matchermatcher=null;

}else{

077

067

index=string.indexOf(temp);

083

matcher=pattern.matcher(string);

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

069

s=decimalFormat.format(obj);

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

091

085

053

079

try{

s=numberFormat.format(obj);

string=computeStirngNoBracket(string);

063

061

}

}

*@return

089

093

publicstaticStringcomputeString(Stringstring){

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

071

*@paramstring

066

}

at(obj);

070

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

}else{

热门小说推荐

最近更新小说