Statistics English alphabet

Source: Internet
Author: User

Design ideas:

Read the English file first, then read one letter at a time, and determine if the word exists in Word, reading one letter at a time until the end, if the character is a newline. Spaces, single quotes, double quotes, commas, periods are the end of a word and the beginning of another word, if the word is present in the word chain + +, if it does not exist then add in the word chain and then use the Loop statement to find the most number of output word chains in the word chain

        ImportJava.io.BufferedReader; ImportJava.io.BufferedWriter; ImportJava.io.FileReader; ImportJava.io.FileWriter; Importjava.io.IOException; ImportJava.util.Iterator; ImportJava.util.TreeMap; ImportJava.util.regex.Matcher; ImportJava.util.regex.Pattern;  Public classZimu { Public Static voidMain (string[] args)throwsIOException {String addr= "Specified text path"; BufferedReader BUFR=NewBufferedReader (NewFileReader (addr)); StringBuffer Sbuf=NewStringBuffer (); String Line=NULL;  while(line = Bufr.readline ())! =NULL) {sbuf.append (line);            } bufr.close (); Pattern expression= Pattern.compile ("[a-za-z]+"); String str1=sbuf.tostring (). toLowerCase (); Matcher Matcher=Expression.matcher (STR1); TreeMap Mytreemap=NewTreeMap (); intn = 0; Object Word=NULL; Object Num=NULL;  while(Matcher.find ()) {Word=Matcher.group (); N++;//                 if(Mytreemap.containskey (Word)) {num=mytreemap.get (word); Integer Count=(Integer) num; Mytreemap.put (Word, count.intvalue ()+ 1); } Else{mytreemap.put (Word,NewInteger (1));// }} System.out.println ("The article reads as follows:");            System.out.println (STR1); System.out.println ("The statistical analysis is as follows:"); System.out.println ("Total number of words in the article:" + n+ "); System.out.println ("The specific information is in the Lwl.txt file of the current directory"); BufferedWriter BUFW=NewBufferedWriter (NewFileWriter ("C:/ijm/lwl.txt")); Iterator ITER=Mytreemap.keyset (). iterator (); Object Key=NULL; Bufw.write ("The file is from:" +addr+ "content is as follows:");            Bufw.write (Sbuf.tostring ());            Bufw.newline ();  while(Iter.hasnext ()) {Key=Iter.next (); SYSTEM.OUT.PRINTLN (Key+":"+Mytreemap.get (key)); Bufw.write (String) key+":"+Mytreemap.get (key));            Bufw.newline (); } bufw.write ("The statistical analysis is as follows:"); Bufw.write ("Total number of words in the article:" + n+ ");            Bufw.newline (); Bufw.write ("Number of different words in the article:" + mytreemap.size () + "Individual");        Bufw.close (); }        }

Statistics English alphabet

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.