숙제는 주어진 문자열에서 주어진 문자의 모양을 계산하는 재귀 적 메서드를 만드는 것입니다. 여기에 지금까지 내 코드입니다 :자바에서 재귀 적 메서드를 사용하여 문자열의 특정 문자 계산하기
import java.util.Scanner;
public class Exercise18_10 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string: ");
String str = sc.next();
System.out.print("Enter a character: ");
String letter = sc.next();
char a = letter.charAt(0);
System.out.println("The count of " + a + " is: " + count(str, a));
}
public static int count(String str, char a) {
int count = str.indexOf(a);
return count;
}
}
이 count
에서, 내가 원하는 문자의 첫 번째 항목을 찾을 수 indexOf
를 사용,하지만 그 이후에 무엇을 할 확실하지 않다.
펜과 종이 만 가지고 있다면 어떻게 할 것인가? –
'indexOf (...)'가 무엇을하는지 알고 있습니까? – Turing85
예 지정한 문자의 첫 항목을 찾습니다. –