class Charcounter {
char crt;
int number;
public static void main(String[] args) { //main
Charcounter array[];
String text;
char c;
int i,j,z,pos;
array = new Charcounter[256];
text = "Hello World";
for(i=0; i<text.length(); i++) //array mit objekten füllen
array[i]=new Charcounter();
i=0;
pos=0;
while(i<text.length()) {
c=text.charAt(i);
for(j=0; j<pos && array[j].crt!=c; j++); //richtig stelle im array suchen
if(c==text.charAt(j)) { //zeichen existiert
array[j].number++;
}
else { //zeichen neu
array[j].crt=c;
array[j].number=1;
pos++;
}
i++;
}
//ausgabe
for(z=0;z<pos; z++)
System.out.println("Das zeichen" + array[z].crt + "ist" + array[z].number + "vorgekommen");
}
}