首页 > 代码库 > 字符串数组统计单词数
字符串数组统计单词数
public class _z {
public static void main(String a[]){
String x[]=new String[]{"Every","day","we","should","smile","on","the","people","around","us"};
int word_w=0;
int word_or=0;
int word_length3=0;
for(int i=0;i<x.length;i++){
System.out.print(x[i]+" ");
}
System.out.println();
for(int i=0;i<x.length;i++){
if(x[i].substring(0,1).equals("w")||x[i].substring(0,1).equals("W")){
word_w++;
}
}
for(int i=0;i<x.length;i++){
if(x[i].indexOf("or")!=-1)
word_or++;
}
for(int i=0;i<x.length;i++){
if(x[i].length()==3)
word_length3++;
}
System.out.println("字母w开头的单词有"+word_w+"个");
System.out.println("单词中含“or”字符串的单词有"+word_or+"个");
System.out.println("长度为3的单词有"+word_length3+"个");
}
}
字符串数组统计单词数