static void getResult() { // 힌트] indexOf(검색어, startIndex);//**startIndex // 찾음 -> 찾음 -> 찾음 -> 못찾으면 break // index용 변수는 -1이 디폴트 String str = "Java란 블라블라Java 블라블라Java Java블라블Java..."; String inputTxt = "Java"; int count = 0; int where = str.indexOf(inputTxt, 0); while (true) { if (where < 0) { System.out.printf("%s가 발견된 횟수는 총 %d회입니다.", inputTxt, count); break; } else { count += 1; where = str.indexOf(inputTxt, where + inputTxt.length()); } } }
'java' 카테고리의 다른 글
Callendar 클래스 없이 달력만들기 (0) | 2013.07.25 |
---|---|
숫자를 한글로 변환(금액단위) (0) | 2013.07.25 |
빼기연산으로 몫과 나머지 구하기 (0) | 2013.07.25 |
별찍기 (0) | 2013.07.25 |
배열 + 제어문으로 중복값 찾기 (0) | 2013.07.25 |