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