import java.io.*;
public class WordCount {
public static void main(String[] args) {
StringReader in = new StringReader("The quick, brown fox jumps over 1 lazy dog");
System.out.println(new WordCount().getWordCount(in));
}
public int getWordCount(Reader in) {
int result = 0;
try {
StreamTokenizer st = new StreamTokenizer(in);
while (st.nextToken() != StreamTokenizer.TT_EOF) {
switch (st.ttype) {
case StreamTokenizer.TT_WORD:
result++;
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
finally {
try {
in.close();
} catch (IOException e) { /* ignore */
}
}
return result;
}
}
public class WordCount {
public static void main(String[] args) {
StringReader in = new StringReader("The quick, brown fox jumps over 1 lazy dog");
System.out.println(new WordCount().getWordCount(in));
}
public int getWordCount(Reader in) {
int result = 0;
try {
StreamTokenizer st = new StreamTokenizer(in);
while (st.nextToken() != StreamTokenizer.TT_EOF) {
switch (st.ttype) {
case StreamTokenizer.TT_WORD:
result++;
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
finally {
try {
in.close();
} catch (IOException e) { /* ignore */
}
}
return result;
}
}