import java.io.*;
import java.util.*;

/** We use this class to count the number of lines, of words, and of 
    tokens in a text file whose name is given as a command line parameter.
 */

public class Wc
{
    public static void main(String[] args) {
	if (args.length != 1) {
	    System.out.println("usage: java Wc filename");
	    System.exit(0); 
	}
	int ccount = 0;		// number of characters counted
	int wcount = 0;		// number of words counted
	int lcount = 0;		// number of lines counted
	Scanner sc = null;
	try {
	    try {
		sc = new Scanner(new File(args[0]));
		while (sc.hasNext()) {
		    String aline = sc.nextLine();
		    lcount++;
		    ccount += aline.length() + 1; // to account for \n
		    Scanner tk = new Scanner(aline);
		    while (tk.hasNext()) {
			tk.next();
			wcount++;
		    }
		}
	    } finally {
		if (sc != null)
		    sc.close();
	    }
	} catch (FileNotFoundException e) {
	    System.out.println(e.getMessage());
	} catch (IOException e) {
	    System.out.println(e.getMessage());
	} 
	System.out.println("\t" + lcount + "\t" + wcount +
			   "\t" + ccount + "\t" + args[0]);
	System.exit(0);
    }
}
