//Letter 1705-2 20173629 He Weihao Packagepaper check weight;ImportJava.io.*;ImportJava.util.*; Public classCheck Weight { Public Static voidMain (string[] args) {Demo (NewFile ("c:\\users\\lenovo\\desktop\\java\\ temporary file \ \ \ \ \ \ \ \")); } Public Static voidDemo (file file) {BufferedReader bfr=NULL;//defining a character read (buffered) stream Try{BFR=NewBufferedReader (NewFileReader (file)); String value =NULL; String newvalue = ""; while((value = Bfr.readline ())! =NULL){//start reading characters from a fileNewValue = Newvalue+value;//deposit in NewValue variable } Char[] ch = newvalue.tochararray ();//Turn newvalue into a character arraytreemap<character,integer> TM =NewTreemap<character,integer> (Collections.reverseorder ()); for(intx = 0;x<ch.length;x++) {Charc =Ch[x]; if(Tm.containskey (c)) {//if the key is present in the TreeMap (tm), the value in the key is taken out, that is, the number of occurrences intConut =Tm.get (c); Tm.put (C,conut+1);//deposit The new value into the TM collection, if the key is the same, the new key will replace the old key, the value changes } Else{tm.put (c,1);//if the key is not present, the first occurrence is then deposited 1 times } } //The following is the removal of keys and values from the TreeMap (tm)Set<map.entry<character, integer>> set =Tm.entryset (); Iterator<map.entry<character, integer>> iter =Set.iterator (); while(Iter.hasnext ()) {Map.entry<character, integer> map =Iter.next (); CharK =Map.getkey (); intv =Map.getvalue (); System.out.print (k+ "(" +v+ ")"); } } Catch(IOException e) {System.out.println ("File read error"); } finally{ Try{ if(bfr!=NULL) Bfr.close (); } Catch(IOException e) {System.out.println ("File Close Error"); } } }}
Verify Duplicate letter Codes