admin 管理员组

文章数量: 887021

将一批单词存入一个字符串数组中,例如:{good,word,work,mean,thank,me,you,or,and} 进行如下处理:

将一批单词存入一个字符串数组中,例如:{"good","word","work","mean","thank","me","you","or","and"}

进行如下处理:

1) 统计含有子字符串or的单词个数;

2) 统计以字符m开头的单词个数。

public class Test {public static void main(String[] args) {String str1[]= {"good","word","work","mean","thank","me","you","or","and"};//1) 统计含有子字符串or的单词个数;//2) 统计以字符m开头的单词个数。int m=0,n=0;int i=0;for(i=0; i<9; i++){//System.out.println(str1[i].indexOf("or"));if(str1[i].indexOf("or")!=-1){m++;}//System.out.println(str1[i].substring(0,1));if(str1[i].startsWith("m")){n++;}}System.out.printf("含有子字符串or的单词个数:%d\n",m);System.out.printf("以字符m开头的单词个数:%d\n",n);}
}

本文标签: 将一批单词存入一个字符串数组中,例如good Word WORK mean thank