• 大小: 0M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-07-10
  • 语言: 其他
  • 标签: 其他  

资源简介

experiment1.zip

资源截图

代码片段和文件信息

package experiment1;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by haol on 2016/11/3.
 */
public class AnalyseStr {

        public static int i = 0;
        //isNumStr 记录是否遍历在数字串中,是的话则数字包括Zero和。并记录数字串的开头 否则 无
        //一旦便利到数字 则一直便利内部i++不跳出while循环,直到遇到非数字和第一个‘.‘
        public static boolean isNumStr = false;

        public List analyStr(String str) throws Exception {
                i = 0;
                isNumStr = false;
                str = str.trim();
                List tokens = new ArrayList();

                int begin = 0;

                while (i < str.length()) {
                        String thisStr = str.substring(i i + 1);
                        if (this.analyseIsNum(thisStr) ) {
                                if (!isNumStr) {
                                        begin = i;
                                }
                                isNumStr = true;

                                this.passNumStr(str);
                                //遍历到下一个非数字的位置
                                i++;
                                if (i + 1 < str.length() && str.substring(i i + 1).equals(“.“)) {
                                        tokens = this.analyseIAfterDot(tokens str begin);
                                } else {
                                        Token token = new Token(“5“ str.substring(begin i) str.substring(begin i) “int“);
                                        tokens.add(token);
                                        isNumStr = false;
                                }
                        } else if (thisStr.equals(“0“)) {
                                if (i+1                                        if(this.analyseIsNum(str.substring(i+1i+2)) || str.substring(i+1i+2).equals(“0“)){
                                                Token token = new Token(“e“ str.substring(i i+1) “ERROR“ “0出现的位置不正确“);
                                                tokens.add(token);
                                                i++;
                                                isNumStr = false;
                                        }else {
                                                tokens = this.analyseIsZero(tokens str);
                                        }
                                }else{
                                        Token token = new Token(“0“ str.substring(i i+1) str.substring(i i+1) “int“);
                                        tokens.add(token);
                                        i++;
                                        isNumStr = false;
                                }
                        } else {
                        /* 分析非数字并判断括号周围是否有误*/
                                tokens = this.analyseIsNotNum(tokens str);
                        }
                }
                return tokens;
        }

        public bool

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-01-09 20:27  experiment1\
     文件        9403  2016-11-17 20:30  experiment1\AnalyseStr.java
     文件        1291  2016-11-17 20:28  experiment1\Complie_1.java
     文件        1582  2016-11-22 22:11  experiment1\FormatOut.java
     文件         549  2016-11-04 23:19  experiment1\read.txt
     文件         773  2016-11-17 22:20  experiment1\ReadText.java
     文件        2257  2016-11-17 20:05  experiment1\Token.java

评论

共有 条评论