Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Letters
- {
- /**
- Counts the frequencies of letters A-Za-z in a string
- @param str a string
- @return an array of 26 counts. The i-th count is the number of occurrences
- of 'A' + i or 'a' + i.
- */
- public int[] letterFrequencies(String str)
- {
- str.toLowerCase();
- int[] result = new int[26];
- char[] arrStr = str.toCharArray();
- for(char a : arrStr)
- {
- if(Character.isLetter(a)){result[Character.getNumericValue(a) - 10] += 1;}
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement