题目:计算字符串中有几个子串 。
程序分析:以空格为分隔符,空格数加一即为子串个数。
public class Prog49{
public static void main(String[] args){
String str = "I come from County DingYuan Province AnHui.";
char[] ch = str.toCharArray();
int count = 0;
for(int i=0;i<ch.length;i++){
if(ch[i]==' ')
count++;
}
count++;
System.out.println("共有"+count+"个字串");
}
}