I have to read the string "hello world"
and output each letter's frequency using only for loops. The instructor hinted that I'd need to use two loops and gave us the following code to begin:
int ch, count;
for (ch ='a'; ch <='z'; ch++) {
//count the number of occurrences in a line
//Print the count>0
}
Edit: I figured I'd necro this question and post the solution I found a year ago due to the fact that this question has been getting a decent amount of hits.
int count;
int value;
for (int i=65; i<91; i++) {
count=0;
for (int j=0; j<S.length; j++) {
value=(int)S[j];
if (value == i) {
count++;
}
}
if (count>0)
System.out.println((char)i+" -- "+count);
}