Advertisement
advictoriam

Untitled

Jan 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. public class Letters
  2. {
  3.    /**
  4.       Counts the frequencies of letters A-Za-z in a string
  5.       @param str a string
  6.       @return an array of 26 counts. The i-th count is the number of occurrences
  7.       of 'A' + i or 'a' + i.
  8.    */
  9.    public int[] letterFrequencies(String str)
  10.    {
  11.       str.toLowerCase();
  12.       int[] result = new int[26];
  13.       char[] arrStr = str.toCharArray();
  14.       for(char a : arrStr)
  15.       {
  16.          if(Character.isLetter(a)){result[Character.getNumericValue(a) - 10] += 1;}
  17.       }
  18.       return result;
  19.    }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement