小编典典

如何计算Java字符串中出现序列的次数?

java

我有一个看起来像的字符串:

"Hello my is Joeseph. It is very nice to meet you. What a wonderful day it is!".

我想计算is字符串中的次数。

如何用Java做到这一点?


阅读 223

收藏
2020-10-12

共1个答案

小编典典

int index = input.indexOf(“is”);
int count = 0;
while (index != -1) {
count++;
input = input.substring(index + 1);
index = input.indexOf(“is”);
}
System.out.println(“No of is in the input is : ” + count);

2020-10-12