SHARE
TWEET

Untitled

advictoriam Jan 23rd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top