Fifth time Assignment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.