Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help  RSS feed

 
stephencheng
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I display the frequency occurence of word? The coding have errors.
//import java.util.collections.*;
import java.util.*;
import java.io.*;
public class occurence{
static public void main(String[] args){
Map words = new TreeMap();
String inpfile = "Doubt is the vestibule\nthrough which all must\npass before they can enter\ninto the temple of wisdom.";
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line, word;
Count count;
try{
while((line = in.readLine()) != null){
StringTokenizer st = new StringTokenizer(line, inpfile);
while (st.hasMoreTokens()){
word = st.nextToken().toLowerCase();
if (words.containsKey(word)){
count = (Count) words.get(word);
count.i++;
}
else{
words.put(word, new Count(word, 1));
}
}
}
}catch (IOException e){}
Set set = words.entrySet();
Interator iter = set.iterator();
while (iter.hasNext()){
Map.Entry entry = (Map.Entry) iter.next();
word = (String) entry.getKey();
count = (Count) entry.getValue();
System.out.println(word+(word.length() < 8 ? "\t\t" : "\t") + count.i);
}
}
}
[ October 22, 2002: Message edited by: stephencheng ]
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're all here to help, but it looks like you're trying to get us to do everything (homework) for you.
Is there a specific part of the assignment you're stuck on?
If you want some help, your best bet is to write as much of your program as possible and when you get stuck, post a specific question.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!