Skip to content

Instantly share code, notes, and snippets.

@ellbur
Created November 9, 2011 05:16
Show Gist options
  • Select an option

  • Save ellbur/1350476 to your computer and use it in GitHub Desktop.

Select an option

Save ellbur/1350476 to your computer and use it in GitHub Desktop.
C0unt1ng L3tt3rs
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