为什么下面的算法不能停止?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);
眼眸繁星
不负相思意
POPMUISE
扬帆大鱼
www说
相关分类