0 Members and 1 Guest are viewing this topic.
StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.
import java.util.Scanner;import java.io.*;import java.lang.*;import java.util.ArrayList;import java.util.List;public class CoutWords { public static void main(String[] args) throws IOException { Scanner in = new Scanner (new File("C:\\Documents and Settings\\100020930\\Desktop\\Lincoln.txt")); String line; ArrayList <String> WordList = new ArrayList <String>(); int [] index = new int[154]; while(in.hasNext()) { line = in.nextLine(); String[] s = line.split("\\s+"); for(String i : s) { if (!(i.equals("-"))) { i = i.replace(",",""); i = i.replace(".",""); if (!(WordList.contains(i.toLowerCase()))) { WordList.add(i.toLowerCase()); } index[WordList.indexOf(i.toLowerCase())]++; } } } int sum = 0; for(int i : index) sum += i; System.out.println(sum); System.out.println(WordList.size()); } public CoutWords() { }}