Site hosted by Angelfire.com: Build your free website today!

Letter Count

If you wish to view the code only, check this page. You can click the links and it should open up in a notepad file.

 

class MyQuotes {
public static void main(String[] arguments) {
String phrase[] = {
"KILL 'EM ALL AND LET GOD SORT THEM OUT",
"FISH SANDWICH",
"THERE'RE AFTER ME LUCKY CHARMS",
"RIDICULOUS LUCKY CAPTAIN RABBIT KING",
"LUCKY CAPTAIN RABBIT KIND NUGGETS ARE FOR THE YOUTH",
"DOOMED DOOMED DOOMED GO HOME NOW",
"I NEED TO GET SOME ORIGINAL QUOTES",
"IT'S GOT PLUS NINE AGAINST OGRES",
"INSERT QUOTE HERE.",
"ZIP ZOP ZUBITY BOB",
"POKEMAN",
"IT TASTES LIKE BURNING",
"FRIENDSHIP TO ME MEANS THAT FOR TWO BUCKS I TAKE YOU OUT BACK AND BEAT YOU WITH A POOL CUE UNTIL YOU HAVE DETACHED RETINAS",
"I'M NOT A GEEK, I'M A LEVEL TWELVE PALADIN",
"I HATE YOU, I HATE THE BANDS YOU LIKE"
};
int[] letterCount = new int[26];
for (int count = 0; count < phrase.length; count++) {
String current = phrase[count];
char[] letters = current.toCharArray();
for (int count2 = 0; count2 < letters.length; count2++) {
char lett = letters[count2];
if ( (lett >= 'A') & (lett <= 'Z') ) {
letterCount[lett - 'A']++;
}
}
}
for (char count = 'A'; count <= 'Z'; count++) {
System.out.print(count + ": " +
letterCount[count - 'A'] +
"\t");
}
System.out.println();
}
}

 

Code taken from:
http://www.samspublishing.com/library/content.asp?b=STY_Java2_24hours&seqNum=108&rl=1

 

 

Comments:

The downside about this program is that it will only work for uppercase letters. Keep that in mind.