• 软件工程项目程序: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

  • 相关阅读:
    菜鸟浅谈软件开发项目管理
    中国准货币体系的概要简析
    使用dockercompose安装wordpress
    货币乘数
    安全测试的相关内容
    TCP三次握手和四次挥手
    HTTP协议相关
    描述浏览器登录的过程
    AJAX相关知识
    什么是热钱
  • 原文地址:https://www.cnblogs.com/yeershao/p/7598198.html
Copyright © 2020-2023  润新知