package com.dev.base.exercise.oct26;
public class Demo {
public static void main(String[] args) {
String s = "goodgoodstudydaydayup";
String target = "good";
int c = count(s,target);
System.out.println(c);
}
public static int count(String s,String target) {
int count = 0;
int index = 0;
while ((index = s.indexOf(target))!=-1) {
s = s.substring(target.length()+index);
count++;
}
return count;
}
}
一个子串在整串中出现的次数
最新推荐文章于 2022-10-24 23:29:20 发布