次の再帰メソッドを作成する必要があります。
public static int countA(String s)
それでも、カウンターと位置変数を宣言せずにこれを行うことは不可能だと思います。そのようです:
public static int countA(String s, int position) {
int count = 0;
if( s.charAt(position) == 'A' )
count++;
if( position + 1 < s.length() ) {
count += countA(s, position + 1);
}
return count;
}
私の方法がリストされているものと同じになるように、どうすれば答えを単純化できますか?
編集: はい、文字列内のすべての A を数えたいと思います。