Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public class charFrequency {
  2.  
  3. public static void main(String[] args) throws IOException {
  4.  
  5. File file1 = new File("terjevigen.txt");
  6. BufferedReader in = new BufferedReader (new FileReader (file1));
  7. System.out.println("Character Frequency");
  8.  
  9. int nextChar;
  10. char ch;
  11.  
  12. int[] count = new int[26];
  13.  
  14. while ((nextChar = in.read()) != -1) {
  15. ch = ((char) nextChar);
  16. ch = Character.toLowerCase(ch);
  17. if (ch >= 'a' && ch <= 'z')
  18. count[ch - 'a']++;
  19. }
  20.  
  21.  
  22. for (int i = 0; i < 26; i++) {
  23. System.out.printf("%c = %d\n", i + 'A', count[i]);
  24.  
  25. }
  26.  
  27.  
  28.  
  29. in.close();
  30.  
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement