Advertisement
911rennsport

A to z Letter Counting

Feb 1st, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1.     public void printLetterDistribution() {
  2.         int[] letterCount = new int[52];
  3.         for(String s: notes) {
  4.             for(char c: s.toCharArray()) { //Looked up the method .toCharArry() on stackoverflow
  5.                 if(c > 'A' && c < 'a') {
  6.                     letterCount[c-'A']++;
  7.                 }
  8.                 if(c > '`') {
  9.                     letterCount[c-'a' + 26]++;
  10.                 }
  11.             }
  12.         }
  13.         for(int i = 0; i < 26; i++) {
  14.             System.out.println((char)(i+'A') + ": " + letterCount[i] + "\t" + (char)(i+'a') + ": " + letterCount[i+26]);
  15.         }
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement