⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex1.java

📁 讲述各种各样的java初始编程 了解编程
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package chenchao4;import java.io.*;import java.util.*;/** * * @author williechen */public class Ex1 {    private String fileName = new String();    private ArrayList<String> lines = new ArrayList<String>();    private HashMap<String, Integer> wordList = new HashMap<String, Integer>();    private void loadFileIntoLines() {        try {            File file = new File(fileName);            FileReader fReader = new FileReader(file);            Scanner sc = new Scanner(fReader);            while (sc.hasNextLine()) {                lines.add(sc.nextLine());            }            sc.close();            fReader.close();        } catch (IOException ioe) {            System.out.println(ioe.getStackTrace());        }    }    private void scanALine(String s) {        String patten = " " + ',' + ';' + '-' + '.' + '。'+ '、' + ',';        StringTokenizer st = new StringTokenizer(s, patten);        while (st.hasMoreTokens()) {                        String word = st.nextToken();            int count = 1;            if (wordList.containsKey(word)) {                count = wordList.get(word);                count++;                wordList.remove(word);            }            wordList.put(word, count);        }    }    private void doStatistics() {        for(String s : lines)            scanALine(s);                int wordSum = 0;                Collection<Integer> countList = wordList.values();        for(int i : countList)            wordSum += i;        int max = Collections.max(countList);                System.out.println("Lines counts is :" + lines.size());        System.out.println("The Total Words Counts is:" + wordSum);        System.out.println("The words used max counts is :" + max);        System.out.println("Below is the WordList:");        System.out.println(wordList);    }    public Ex1(String fileName) {        this.fileName = fileName;    }    public static void main(String[] args) {        Ex1 t = new Ex1("D:\\cloze.txt");        t.loadFileIntoLines();        t.doStatistics();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -