Scanner sc=new Scanner(System.in);
System.out.println("请输入第一个字符串:");
String s1=sc.next();
System.out.println("请输入第二个字符串:");
String s2=sc.next();
if(s1.length()<s2.length()) {
System.out.println("出现了0次");
sc.close();
return;
}
int index=s1.indexOf(s2);
int count=0;
while(index !=-1) {
count++;
index=s1.indexOf(s2,index+1);
}
System.out.println("共出现了"+count+"次");
sc.close();