I need to find an algorithm which counts the letters in any string (e.g. "cabababb") and the output must be in a alphabetical manner(e.g. a: 3, b: 4, c:1 etc.) . There is no need to distinguish between upper and lower case letters. I am not allowed to youse a HashMap.
This is my code till now: I'ts not working, I think I've got the wrong strategy here. Can you help me please?
public class Stringray extends MiniJava{
public static void main(String[] args) {
// Texteingabe
String input = readString("Geben Sie einen Text ein: ");
String output = "";
int i = 0;
// H?ufigkeit der Buchstaben
int count = 0;
char letter = 'a';
while(i < input.length()) {
while(i < input.length()) {
if(input.charAt(i) == letter) {
while(i < input.length()) {
count++;
i++;
}
output = output + letter + ": " + count + " ";
}
i++;
}
letter++;
}
write(output);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…