Import java.util.*;
Import java.io.*;
public class Wordsrate {public static void main (string[] args) throws Exception {
BufferedReader infile = new BufferedReader (New FileReader ("D:\\a_tale_of_two_cities.txt"));
string string;
String file = null;
while ((string = Infile.readline ()) = null) {
File + = string;
}
File = File.tolowercase ();
File = File.replaceall ("[^a-za-z]", "");
File = File.replaceall ("\\s+", "" ");
String words[];
Words = File.split ("\\s+");
map<string, integer> hashMap = new hashmap<string, integer> ();
for (int i = 0; i < words.length; i++) {
String key = Words[i];
if (hashmap.get (key) = null) {
int value = ((Integer) Hashmap.get (Key)). Intvalue ();
value++;
Hashmap.put (Key, new Integer (value));
} else {
Hashmap.put (Key, New Integer (1));
}
}
map<string, object> treeMap = new treemap<string, object> (HASHMAP);
map<string, object> treeMap1 = new treemap<string, object> (HASHMAP);
BufferedWriter bw = new BufferedWriter (New FileWriter ("Result1.txt"));
Iterator iter = Treemap.entryset (). Iterator ();
String ss1[]=new string[treemap.size ()];;
int ss2[]=new int[treemap.size ()];
int i=0;
while (Iter.hasnext ()) {
Map.entry Entry = (map.entry) iter.next ();
int val = (Integer) entry.getvalue ();
String key = (string) entry.getkey ();
Ss1[i]=key;
Ss2[i]=val;
i++;
}
int svalue=0;
String skey= "";
for (int j=0;j<ss2.length;j++) {
for (int k=0;k<i;k++) {
if (Ss2[j]>ss2[k]) {
SVALUE=SS2[J];
SKEY=SS1[J];
SS2[J]=SS2[K];
SS1[J]=SS1[K];
Ss2[k]=svalue;
Ss1[k]=skey;
}
}
}int[] strlengths = new Int[ss2.length];
for (int j=0;j<ss2.length; J + +) {
STRLENGTHS[J] = Ss1[j].length ();
}
Scanner s=new Scanner (system.in);
System.out.println ("Please enter the word you are looking for:");
String str = S.next ();
int count=0;
for (int j=0;j<words.length;j++)
{if (Str.equals (Words[j])) count++;}
System.out.println ("The word frequency to find is:" +count);
for (int j=0;j<ss2.length;j++) {
if (strlengths[j]>=4)
System.out.println (ss1[j]+ "=" +ss2[j]);
Bw.write (ss1[j]+ "=" +ss2[j]);
Bw.newline ();
Bw.flush ();
}
}
}
Operation Result:
:
Fifth time Assignment