import java.io.* ; import java.util.*; public class SoneTootlus{ String failinimi; FileReader failist; Hashtable ht ; private SoneTootlus(String failinimi ){ this.failinimi =failinimi ; ht=new Hashtable(); try{ failist =new FileReader(failinimi); this.readToTable(); this.checkFirst(); }catch(Exception e){System.out.println("Tekkis viga initil ") ;} } private void checkFirst() throws Exception { BufferedReader br=new BufferedReader(new FileReader(failinimi)); String first=br.readLine(); if(ht.containsKey(first)){ int mitu=((Counter)(ht.get(first))).getNumber(); if(mitu>1){ System.out.println("Esimene "+first +" esines "+mitu +" korda") ; }else{System.out.println(first+" rohkem ei esine ") ;} }else{System.out.println(first+" rohkem ei esine ") ; } } private void readToTable() throws Exception { try{ BufferedReader br=new BufferedReader(failist); String sona=""; while((sona=br.readLine())!=null) { if(ht.containsKey(sona)){ ((Counter)(ht.get(sona))).oneMore(); } else { ht.put(sona,new Counter()); } } this.analyzeTable(); }catch(Exception e){e.getMessage() ;} } private void analyzeTable()throws Exception { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); int i=1 ; for(Enumeration e=ht.keys();e.hasMoreElements(); i++ ){ String key=((String)(e.nextElement())); System.out.println(key +" esines "+((Counter)(ht.get(key))).getNumber()); if (i%15==0){ bf.readLine(); } } } public static void main(String args[]){ if(args.length!=1){System.out.println("Commnad line error !");System.exit(0);} else{System.out.println("Fail oli " +args[0]); new SoneTootlus(args[0]); } } } class Counter{ int i; Counter(){i=1;} void oneMore(){i++ ; } int getNumber(){return i ;} }