Joke Collection Website - Public benefit messages - Find a JAVA applet that requires statistical output of word frequency in English paragraphs.

Find a JAVA applet that requires statistical output of word frequency in English paragraphs.

Import java.util.ArrayList;

Import java.util.collections;

Import java.util.comparator;

Import java.util.iterator;

Import java.util.list;

Import java.util.set;

Import java.util.treeset;

Public articles {

//Save the content of the article

String content;

string[]raw words;

String[] word;

int[]wordFreqs;

Public article () {

content =

}

public void splitWord() {

Final character space ='';

Content = content.replace('\'', space). Replace (',',space)

. Replace ('.'), space);

Content = content.replace (',space). Replace (')', space)

. Replace ('-',space);

raw words = content . split(" \ \ s+");

}

public void countWordFreq() {

Set< string & gtset = new tree set< string & gt ();

for (String word : rawWords) {

set . add(word);

}

Iterator ite = set. Iterator ();

List & lt string & gtwordsList = new ArrayList & lt string & gt ();

List & lt integer & gtfreqList = new ArrayList & lt integer & gt ();

while (ite.hasNext()) {

String word =(String)ite . next();

int count = 0;

for (String str : rawWords) {

if (str.equals(word)) {

count++;

}

}

words list . add(word);

freq list . add(count++);

}

Words = wordsList.toArray (new string [0]);

wordFreqs = new int[freq list . size()];

for(int I = 0; I< freqlist.size (); i++) {

wordFreqs[I]= freq list . get(I);

}

}

Public void sort () {

Category words {

Private string words;

Private int freq

public Word(String word,int freq) {

this.word = word

this.freq = freq

}

}

The WordComparator class implements a comparator {

public int compare(Object o 1,Object o2) {

Word Word 1 =(Word)o 1;

Word Word 2 =(Word)O2;

if(word 1 . freq & lt; word2.freq) {

Returns1;

} else if(word 1 . freq & gt; word2.freq) {

return- 1;

} Otherwise {

int len 1 = word 1 . word . trim()。 Length ();

int len2 = word2.word.trim()。 Length ();

string min = len 1 & gt; len2? word 2 . word:word 1 . word;

string max = len 1 & gt; len2? word 1 . word:word 2 . word;

for(int I = 0; I < Minimum length (); i++) {

if(min . charat(I)& lt; Maximum charat (i)) (

Returns1;

}

}

Returns1;

}

}

}

List wordList = new ArrayList & ltWord & gt();

for(int I = 0; I & ltwords.lengthi++) {

wordList.add(new Word(words[i],wordFreqs[I]);

}

Collections.sort(wordList,new word comparator());

for(int I = 0; I< wordlist.size (); i++) {

Word wor =(Word)Word list . get(I);

words[I]= wor . word;

wordFreqs[I]= wor . freq;

}

}

public void printResult() {

system . out . println(" Total "+words . length

+"Different words are used in the content!" );

for(int I = 0; I & ltwords.lengthi++) {

system . out . println(wordFreqs[I]+" "+words[I]);

}

}

Public static void main(String[] args) {

Article a = new article ();

a . content = " sssssssssaadwerqwersssdfsdftrytyum 1242357689235 cvbbnm,masdfasdfasdfasdf,fasdf . asdfasdfasdfasdfaasdfasdf ";

a . split word();

a . count wordfreq();

a . sort();

a . print result();

}

}

Run it to see if it is successful, it is really a semicolon error! It's changed now!