计算字符串中子串出现的次数
2018-04-06 20:55
288 查看
/**
* 计算字符串中子串出现的次数
*
* @author Dreamweaver
*
*/
public class Demo49 {
public static void main(String[] args) {
String str = "abcqwegdslabcsdlfjabcjsdo";
// 定义一个子串
String s = "abc";
// 统计次数
int count = 0;
while (true) {
// 返回第一次出现子串的索引
int index = str.indexOf(s);
if (index!= -1) {
str = str.substring(index + s.length(), str.length()-1);
count++;
} else {
break;
}
}
System.out.println("子字符串一共在字符串中出现了" + count + "次");
}
}
* 计算字符串中子串出现的次数
*
* @author Dreamweaver
*
*/
public class Demo49 {
public static void main(String[] args) {
String str = "abcqwegdslabcsdlfjabcjsdo";
// 定义一个子串
String s = "abc";
// 统计次数
int count = 0;
while (true) {
// 返回第一次出现子串的索引
int index = str.indexOf(s);
if (index!= -1) {
str = str.substring(index + s.length(), str.length()-1);
count++;
} else {
break;
}
}
System.out.println("子字符串一共在字符串中出现了" + count + "次");
}
}
相关文章推荐
- 计算字符串中子串出现的次数
- 程序49:计算字符串中子串出现的次数
- 五十道编程小题目 --- 49 计算字符串中子串出现的次数 java
- Java 中计算字符串中子串出现的次数
- 输入一个字符串,计算该字符串中子串出现的次数
- 4.3输入一个字符串,计算字符串中字串中子串出现的次数
- C#计算字符串中子串出现次数的另类方法
- c语言计算字符串中子串出现的次数
- 输入一个字符串,计算字符串中子串出现的次数
- java 计算字符串中子串出现的次数
- 题目:计算字符串中子串出现的次数
- 【程序49】 题目:计算字符串中子串出现的次数
- 计算字符串中子串出现的次数
- java 计算字符串中子串出现的次数
- java经典算法_031计算字符串中子串出现的次数
- 输入一个字符串,计算字符串中子串出现的次数
- 计算字符串中子串出现的次数
- 计算字符串中子串出现的次数
- 计算字符串中子串出现的次数
- 自己编写的一个求字符串中子串出现次数计算小程序字串长度为2