标签:style blog color ar java for sp on 2014
.如何统计String中有多少个单词?
public class CountWord { public static int countWord(String s){ int count=0; int word=0; for(int i=0;i<s.length();i++){ if("".equals(s.charAt(i))) word=0; else if(word==0) { word=1; count++; } } return count; } public static void main(String args[]){ String s="I am Jiang wei wei"; System.out.print(s); System.out.println("单词的个数为:"+countWord(s)); } }
标签:style blog color ar java for sp on 2014
原文地址:http://blog.csdn.net/dq3wrr/article/details/40746955