PPT Slide
public class CountWords {
static public void main(String[] args) {
HashSet words = new HashSet();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String delim = " \t\n.,:;?!-/()[]\"\'";
while ((line = in.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line, delim);
while (st.hasMoreTokens()) {
words.add(st.nextToken().toLowerCase());
} catch (IOException e) {}
System.out.println("Total number of words: " + count);
System.out.println("Number of different words: " + words.size());