- <div class="blockcode"><blockquote>Stirng max = "woaiheimajavaandroidios,javahelloworldjavaios";//定义长字符串
- String min = "java";//定义小字符串
- int count = 0;//定义统计变量<p style="line-height: 30px; text-indent: 2em;"></p><p style="line-height: 30px; text-indent: 2em;"></p><div align="left">
- </div>int index = max.indexOf(min);//定义索引,这里有疑问,老师讲的是直接给index赋值为0,为什么我这样赋值就不行了?
- while(index != -1) {<p style="line-height: 30px; text-indent: 2em;"></p><div align="right"><ol><li>
- </li></ol></div>count++;
- max = max.substring(index+min.length());//这行总是报错StringIndexOutOfBoundsException请大家帮忙分析一下
- }
- System.out.println(min+"共出现"+count+"次");
复制代码
|
|