public class Str{
public static void main(String[] args){
String sk="lologabecleloeoliollosencloejsllllesnlo";
String k=sk.substring(0,2);
System.out.println(sk+"\n"+k);
System.out.println(strMany(sk,k));
}
static int strMany(String src,String sub){
int num=0;
char c;
char d=sub.charAt(0);
for(int i=0;i<=src.length()-sub.length();i++){
c=src.charAt(i);
if(c==d){
try{
String sb=src.substring(i,sub.length());
if(sub.equals(sb)) {
num++;
i+=sub.length()-1;
}
}catch(StringIndexOutOfBoundsException e){
System.out.println("error!");
e.printStackTrace();
}
}
}
return num;
}
}
编译可以通过,但是。。。。看图:不知道哪里有问题?谢谢
public static void main(String[] args){
String sk="lologabecleloeoliollosencloejsllllesnlo";
String k=sk.substring(0,2);
System.out.println(sk+"\n"+k);
System.out.println(strMany(sk,k));
}
static int strMany(String src,String sub){
int num=0;
char c;
char d=sub.charAt(0);
for(int i=0;i<=src.length()-sub.length();i++){
c=src.charAt(i);
if(c==d){
try{
String sb=src.substring(i,sub.length());
if(sub.equals(sb)) {
num++;
i+=sub.length()-1;
}
}catch(StringIndexOutOfBoundsException e){
System.out.println("error!");
e.printStackTrace();
}
}
}
return num;
}
}
编译可以通过,但是。。。。看图:不知道哪里有问题?谢谢