public class TestString {
public static void main(String[] args) {
String s="peter piper picked a peck of pickled peppers";
System.out.println(s);
//将这些单词以空格进行拆分放进一个String类型的字符串数组里
String[] words=s.split(" ");
int count=0;
for(int i=0;i<words.length;i++) {
String word=words[i];
//判断每个单词的首字母
if(word.charAt(0)=='p') {
count++;
}
}
System.out.println(count);
}
}