日期:2014-05-20  浏览次数:20700 次

这个题怎么做解呢?急用……
用户输入两个字符串str1,str2,返回字符串str1在str2中的出现次数,如:str1(aba),str2(2dabab2)返回2,不可以用indexof和substring方法,怎么解答这个题目啊????

------解决方案--------------------
用正则表达式

Pattern p=Pattern.compile("aba");

Matcher m=p.matcher(str);//str 是要匹配的字符串

int i=0;

while(m.find){

m.group();//匹配的字符串,不要也行

i++;

}

System.out.println("aba的个数是:"+i);
------解决方案--------------------
http://baike.baidu.com/view/659777.htm