zoukankan      html  css  js  c++  java
  • 简单的字数统计

    // $Id: wc.java,v 1.2 2001/05/31 22:56:19 doug Exp $
    // http://www.bagley.org/~doug/shootout/
    // with help from Dirus@programmer.net
    
    import java.io.*;
    import java.util.*;
    import java.text.*;
    
    // this program modified from:
    //   http://cm.bell-labs.com/cm/cs/who/bwk/interps/pap.html
    // Timing Trials, or, the Trials of Timing: Experiments with Scripting
    // and User-Interface Languages</a> by Brian W. Kernighan and
    // Christopher J. Van Wyk.
    
    public class wc {
    public static void main(String[] args) {
    int nl = 0, nw = 0, nc = 0;
    
    try {
    byte[] buff = new byte[4096];
    boolean inword = false;
    int length;
    
    while ((length = System.in.read(buff)) != -1) {
    nc += length;
    for(int i = 0; i < length; i++) {
    char c = (char)buff[i];
    if (c == '\n')
    ++nl;
    if (Character.isWhitespace(c))
    inword = false;
    else if (inword == false) {
    ++nw;
    inword = true;
    }
    }
    }
    } catch (IOException e) {
    System.err.println(e);
    return;
    }
    System.out.println(Integer.toString(nl) + " " +
    Integer.toString(nw) + " " +
    Integer.toString(nc));
    }
    }
    
    关于作者: 王昕(QQ:475660) 在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
    目前维护的开源产品:https://gitee.com/475660
  • 相关阅读:
    loopback 03
    loopback 02
    loopback 01
    node.js整理 02文件操作-常用API
    node.js整理 01代码的组织和部署
    express-21 静态内容
    coffeeScript学习02
    coffeeScript学习01
    jade学习02
    Android 读取Assets中资源
  • 原文地址:https://www.cnblogs.com/starcrm/p/1337670.html
Copyright © 2011-2022 走看看