निम्नलिखित एल्गोरिथ्म मेरे लिए क्यों नहीं रुक रहा है? (str वह स्ट्रिंग है जिसे मैं खोज रहा हूं, findStr वह स्ट्रिंग है जिसे मैं खोजने की कोशिश कर रहा हूं)
String str = "helloslkhellodjladfjhello";
String findStr = "hello";
int lastIndex = 0;
int count = 0;
while (lastIndex != -1) {
lastIndex = str.indexOf(findStr,lastIndex);
if( lastIndex != -1)
count++;
lastIndex += findStr.length();
}
System.out.println(count);