zoukankan      html  css  js  c++  java
  • 软件工程项目程序:WC

    1:代码来源:http://yuncode.net/code/c_5087c8e4cd77190

    2:Platform:Eclipse

          Language:Java

    3:Bug:暂时没有

    4. Function improvement:实现对文件里的字符,单词以及行数的统计。

    5:代码:

    import java.io.*;

    /**
    * 统计文本文件的行数,单词书,字节数
    */
    class WordCount {
    public static int words = 1;
    public static int lines = 1;
    public static int chars = 0;

    public static void wc(InputStream f) throws IOException {
    int c = 0;
    boolean lastNotWhite = false;
    String whiteSpace = " ";
    while ((c = f.read()) != -1) {
    chars++;
    if (c == ' ') {
    lines++;
    }
    if (whiteSpace.indexOf(c) != -1) {
    if (lastNotWhite) {
    words++;
    }
    lastNotWhite = false;
    } else {
    lastNotWhite = true;
    }
    }
    }

    public static void main(String args[]) {
    FileInputStream f;
    try {
    if (args.length == 0) { // We're working with stdin
    f = new FileInputStream("c:/123.txt");
    wc(f);
    } else { // We're working with a list of files
    for (int i = 0; i < args.length; i++) {
    f = new FileInputStream(args[i]);
    wc(f);
    }
    }
    } catch (IOException e) {
    return;
    }
    System.out.println(lines + "行 " + words + "个单词 " + chars + "个字节");
    }
    }

    6:github地址:https://github.com/yeershao/hello-world/commit/9e6930db18fd409a3513318ed922d4fb67bb19a1

  • 相关阅读:
    记一次bash脚本报错原因
    说说JSON和JSONP,也许你会豁然开朗,含jQuery用例(转载)
    python 正则空格xa0实录 与xpath取 div 里面的含多个标签的所有文字
    python3的时间日期处理
    easyui的 一些经验
    hash是什么?
    vue.js 入门
    python __nonzero__方法
    Jmeter之『并发』
    Docker之网络篇
  • 原文地址:https://www.cnblogs.com/yeershao/p/7598198.html
Copyright © 2011-2022 走看看