You need to use some built in methods for String in Java.
In Java 1.7 u 4
You can use a switch statement for both characters and strings if (you need whole worlds).
//An int Array with 26 rows, each element representing a letter.
int characterCount = new int;
for (int i = 0; i < yourString.length; i++)
char temp = yourString.charAt(i);
case 'a' :
characterCount += 1;
It is easier to do this with a HashMap or LinkedHashMap, but I figured you have to do it something like this. All you need now is a method that goes through the array finds the max number, get that index, that index translates to a character, like index 0 = a, or index 5 = f.
You then have to start search again and this time ignore the old max number, but look for the new max. You can do this with something like this pseudo code:
Edited by RagingCain - 5/10/12 at 9:38am
public String findMax(characterCount)
String solution = "";
int oldMax = 0;
int currentMax = 0;
int maxIndex = 0;
int count = 0;
while(count <= characterCount.length)
Go through each time, comparing to oldMax. When finished,
currentMax's index is saved and sent to below switch to converted
to letter, then you go back in with a new oldMax that matched the
last currentMax value. You want to make sure that you are less than
or equal to oldMax value, and repeat till you have reached a total number
of the array, and account for size 0 so you don't print characters that are 0.
each index accounts for a letter, if count is 0
solution += "A"
You can't just use Array Sort because then the data is meaningless, due to it being only useful in order. Its up to you to find the maxes yourself.