package com.ligong;
public class Demo49 {
public static void main(String[] args) {
/* 【程序49】
题目:计算字符串中子串出现的次数*/
String str = "I come from County DingYuan Province AnHui.";
char[] chars = str.toCharArray();
int count=0;
for (int i = 0; i < chars.length; i++) {
if (chars[i]==' '){
count++;
}
}
System.out.println(count+1);
}
}
计算字符串中子串出现的次数,以空格为分隔符
最新推荐文章于 2024-08-21 10:11:50 发布