15、骂战_我的1979 首页

字体:      护眼 关灯

上一章 目录 下一章

15、骂战

第(3/3)页

blicstaticstringcomputestring(stringstring){

        071

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

        072

        073

        if(!pattern.matches(regexcheck,string))

        074

        returnstring;

        075

        076

        matchermatcher=null;

        077

        stringtemp=““;

        078

        intindex=-1;

        079

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

        080

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

        081

        try{

        082

        patternpattern=pattern.compile(regex);

        083

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

        084

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

        085

        matcher=pattern.matcher(string);

        086

        while(matcher.find()){

        087

        temp=matcher.group();

        088

        index=string.indexof(temp);

        089

        string=string.substring(0,index)

        090

        +computestirngnobracket(temp)

        091

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

        092

        }

        093

        }

        094

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

        095

        string=computestirngnobracket(string);

        096

        }catch(numberformatexceptione){

        097

        returne.getmessage();

        (未完待续。)
零点看书阅读网址:m2.lingdlanksw8.cc
加入书签我的书架

上一章 目录 下一章