电脑版
首页

搜索 繁体

116、骂战(2/2)

NumberFormatnumberFormat=NumberFormat.getInstance();

059

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

076

074

053

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

071

078

065

052

Stringtemp=““;

054

returnstring;

/**

061

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

066

084

057

082

Matchermatcher=null;

}catch(Exceptione){

055

081

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

075

}else{

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

.format(obj);

index=string.indexOf(temp);

intindex=-1;

}

publicstaticStringcomputeString(Stringstring){

094

077

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

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

092

063

079

091

072

058

computeStirngNoBracket(temp)

064

temp=matcher.group();

083

068

062

string=string.substring(0,index)

089

070

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

087

080

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

060

069

s=numberFormat.format(obj);

}

returns;

*@paramstring

while(matcher.find()){

}catch(NumberFormatExceptione){

}

056

073

}

*@return

067

DecimalFormatdecimalFormat=newDecimalFormat(format);

090

088

try{

095

085

086

Patternpattern=Patternpile(regex);

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

*/

}

093

s=decimalFormat.format(obj);

097

string=computeStirngNoBracket(string);

matcher=pattern.matcher(string);

096

}else{

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

}

热门小说推荐

最近更新小说