/**
 * A program that emulates a simple version of the Unix command wc.
 * The program takes a file name on the command line, or uses the standard
 * input if no file name is given, and returns there numbers that report
 * the total number of lines, words, and characters in the file.
 */

import java.io.*;	// For InputStream, FileInputStream, and read()


class WC{

    public static void main( String[] arg )
        throws IOException
    {
        InputStream in;			// Declare var of type InputStream
        if ( arg.length == 0 )		// Check for command line param
            in = System.in;		// Default input stream
        else
            in = new FileInputStream( arg[0] );	// Open command line file

        int ch;
        int charCt;			// Count of all characters
        int wordCt = 0;
        int lineCt = 0;
        int spaces = 0;			// Count of whitespace chars
        boolean readingWS = true;

        for ( charCt = 0; (ch = in.read()) != -1; charCt++ ){
            if ( Character.isWhitespace( (char)ch ) ){
                spaces++;
                if ( ch == '\n' ) lineCt++;
                readingWS = true;
                }
            else if ( readingWS ) {	// Reading new word?
                    wordCt++;
                    readingWS = false;
                 }
        }

        System.out.print( "\t" + lineCt + "\t" + wordCt + "\t" 
                            + charCt );
        if ( arg.length != 0 )
            System.out.println( " " + arg[0] );
        else
            System.out.println( );
    }
}
