116、骂战(1 / 1)

请稍后章节错误

&n.z

002

003

&nrtjava.text.DecimalFormat;

004

&nrtjava.text.Numrmat;

005

&nrtjava.text.SimpleDateFormat;

006

&nex.Matcher;

007

&nex.Pattern;

008

009

&nrtUtil{

010

011

/**

012

*格式化日期

013

&nbj日期对象

014

&nrmat格式化字符串

015

*@return

016

*/

017

purmatDate(Ormat){

018

&nbjnull)

019

return““;

020

021

&nsString.valueOf(obj);

022

&nrmatnull||““.equals(format.trim())){

023

&nrmat“yyyy-MM-dd“;

024

}

025

try{

026

&nrmatdateFormatnewSimpleDateFormat(format);

027

&nrmat.format(obj);

028

&nne){

029

}

030

returns;

031

}

032

033

/**

034

*格式化数字

035

&nbj数字对象

036

&nrmat格式化字符串

037

*@return

038

*/

039

purmatNumrmat){

040

&nbjnull)

041

return““;

042

043

&nsString.valueOf(obj);

044

&nrmatnull||““.equals(format.trim())){

045

&nrmat“#.00“;

046

}

047

try{

048

&nat){

049

&nrmat.contains(“%“)){

050

&netPercentInstance();

051

&nrmat.format(obj);

052

}else{

053

&nrmatdecimalFormatnewDecimalFormat(format);

054

&nrmat.format(obj);

055

}

056

}else{

057

&netInstance();

058

&nrmat.format(obj);

059

}

060

&nne){

061

}

062

returns;

063

}

064

065

/**

066

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

067

&n

068

*@return

069

*/

070

publicstaticStrinputeString(Stringstring){

071

&nregexCheck“\\(\\)\\d\\+\\-\\*/\\.*“;//是否是合法的表达式

072

073

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

074

&n;

075

076

Matchermatchernull;

077

&ntemp““;

078

intindex-1;

079

&nregex“\\(\\d\\.\\+\\-\\*/+\\)“;//提取括号表达式

080

&nstring.receAll(“\\s“,““);//去除空格

081

try{

082

PatternpatternPatternpile(regex);

083

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

084

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

085

matcherpattern.matcher(string);

086

while(matcher.find()){

087

&nup();

088

&n.indexOf(temp);

089

&nstring.su(0,index)

090

&nBracket(temp)

091

&n.su(index+temp.lenh());

092

}

093

}

094

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

095

&n);

096

&nrmatExceptione){

097

&netMessage();(未完待续。)

site stats