public class b {
public static void main(String[] args) {
String str1 = "dsasdsadsdsdvgcsds";
String str2 = "ds";
//定义一个计数器count
int count = 0;
for (String tmp = str1; tmp != null && tmp.length() >= str2.length(); tmp = tmp.substring(1)) {
if (tmp.indexOf(str2) == 0) {
count++;
}
}
System.out.println("ds出现的次数" + count);
}
}