编写一个方法,输出在一个字符串中,指定字符串出现的次数。
public class yanzhuo {
public static void method(String a, String b) {
int t = 0;
for (int i = 0; i <= a.length() - b.length(); i++)
if (b.regionMatches(0, a, i, b.length())) {
i += b.length() - 1;
t++;
}
System.out.println("字符串" + a + "中" + b + "出现了" + t + "次");
}
public static void main(String[] args) {
method("dsadsdsasss", "ss");
}
}
运行结果:
最后
以上就是大胆板凳最近收集整理的关于编写一个方法,输出在一个字符串中,指定字符串出现的次数。的全部内容,更多相关编写一个方法,输出在一个字符串中,指定字符串出现内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复