文字列を読み取り、"hello world"
forループのみを使用して各文字の頻度を出力する必要があります。インストラクターは、2つのループを使用する必要があることをほのめかし、開始するために次のコードを提供しました。
int ch, count;
for (ch ='a'; ch <='z'; ch++) {
//count the number of occurrences in a line
//Print the count>0
}
編集:この質問はかなりのヒット数を獲得しているという事実のために、私はこの質問をネクロして、1年前に見つけた解決策を投稿すると思いました。
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);
}