한 문자열이 다른 문자열에 몇 번 나타나는지 알아 내려고합니다. 테스트를 위해 wordOne에는 "ea"를 사용하고 wordTwo에는 "Ilikedthebestontheeastbeachleast"를 사용하고 있습니다. 내 출력은 내 "appearance"변수에 대해 0을 반환합니다.이 변수는 "ea"가 wordTwo에 나타나는 횟수를 저장해야합니다.
다음은 관련 코드 섹션입니다.
int wordTwoLength = wordTwo.length();
System.out.println(wordTwoLength);
while (wordTwoLength > 0)
{
positionCount = wordTwo.indexOf(wordOne, positionCount);
appearances = appearances++;
wordTwoLength = (wordTwoLength - positionCount);
}
System.out.println(appearances);
무슨 뜻이야
appearances = appearances++;
이렇게하면 외모가 항상 0이됩니다.
그냥 외모가 아니야 ++?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다