Created
November 9, 2011 05:16
-
-
Save ellbur/1350476 to your computer and use it in GitHub Desktop.
C0unt1ng L3tt3rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Stuff { | |
| public static void main(String[] args) { | |
| String text = "más letras"; | |
| int[] counts = new int[26]; | |
| for (int z=0; z<26; z++) { | |
| for (int q=0; q<text.length(); q++) { | |
| char here = text.toLowerCase().charAt(q); | |
| char letter = (char)('a' + z); | |
| if (here == letter) { | |
| counts[z]++; | |
| } | |
| } | |
| } | |
| for (int i=0; i<26; i++) { | |
| if (counts[i] != 0) { | |
| System.out.println((char)('a' + i) + ": " + counts[i]); | |
| } | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment