Alex9090

JAVA LAB 8

Apr 20th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package JavaApplication26;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.util.HashMap;
  5. import java.util.Scanner;
  6. import java.util.Set;
  7.  
  8.  
  9. public class JavaApplication26 {
  10.  
  11. public static void main(String[] args) throws FileNotFoundException
  12. {
  13. Scanner sc=new Scanner (new File("input.txt"));
  14. HashMap<String,Integer> hash=new HashMap<String,Integer>();
  15. while(sc.hasNext())
  16. {
  17. String cuv=sc.next( );
  18. if(hash.containsKey(cuv))
  19. {
  20. hash.put(cuv,1+hash.get(cuv));
  21. }
  22. else hash.put(cuv,1);
  23. }
  24.  
  25. Set<String> Keys=hash.keySet();
  26. for(String var: Keys)
  27. {
  28. System.out.println(var+" "+hash.get(var));
  29. }
  30. //Set<Entry<String.Integer>>entries
  31.  
  32. }
  33.  
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment