다음 코드가 있습니다. 내가하고 싶은 것은 특정 캐릭터의 빈도를 세는 것이지만, 할 수 없다. 아무도 힌트를 제공 할 수 있습니까? 이자바에서 특정 문자의 빈도를 계산하십시오.
public static int countOccurance(String inputString, String key) {
int index = 0;
int fromIndex = 0;
int result = 0;
if (inputString == null || key == null) {
return 0;
}
while ((index = inputString.indexOf(key, fromIndex)) != -1) {
result++;
fromIndex = index + key.length;
}
return result;
}
첫 번째 'i ++'는 관계가 없습니다. – trutheality
디버거를 사용해 보셨습니까? –