これまでのところ、これは私が試したことです:
public class CharacterCounter {
public static void main(String[] args){
String string = "sashimi";
int count = 0;
for(int i =0; i < string.length(); i++){
if(string.charAt(i) == 'i'){
count++;
}
}
System.out.println("The number of letter i is " + count);
}
}
出力:
The number of letter i is 2
しかし、私がやりたいことは、プログラムが最も出現した文字をカウントすることです。
たとえば、文字列がSASHIMIの場合、出力は次のようになります。
the number of letter S is 2
the number of letter I is 2
私はこの問題で立ち往生しています。あなたの助けが必要です。ありがとう。