Verify Duplicate letter Codes

Source: Internet
Author: User

//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

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.