tdulik

Histogram of words in Java using HashTable

Oct 28th, 2020
1,104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package histogram_words;
  2.  
  3. import java.io.*;
  4. import java.util.Scanner;
  5.  
  6. public class Histogram {
  7.  
  8.     public static void main(String[] args) {
  9.         try {
  10.             Scanner s=new Scanner(new File("short.txt"));
  11.             MyHashTable table=new MyHashTable(1000);
  12.             while (s.hasNext()) {
  13.                 String word=s.next();
  14.                 int occurence=table.get(word);
  15.                 table.add(word, occurence+1);
  16.             }
  17.             System.out.print(table);
  18.         } catch (FileNotFoundException e) {
  19.             // TODO Auto-generated catch block
  20.             e.printStackTrace();
  21.         }
  22.        
  23.     }
  24.  
  25. }
  26.  
RAW Paste Data