设有一个由10个英文单词构成的字符串数组要求: 1.统计以字母w开头的单词数 统计单词含“or”字符串的单词数目 统计长度为3的单词数目Java代码
时间: 2023-10-23 18:13:20 浏览: 107
统计单词个数&&将字符串中连续出现的数字放进一维数组
4星 · 用户满意度95%
```
public class Test {
public static void main(String[] args) {
String[] strArray = new String[]{"world", "wide", "web", "javascript", "word", "oranges", "apple", "foreign", "microsoft", "order"};
int wCount = 0;
int orCount = 0;
int length3Count = 0;
for (String str : strArray) {
if (str.startsWith("w")) {
wCount++;
}
if (str.contains("or")) {
orCount++;
}
if (str.length() == 3) {
length3Count++;
}
}
System.out.println("以字母w开头的单词数目:" + wCount);
System.out.println("含有字符串or的单词数目:" + orCount);
System.out.println("长度为3的单词数目:" + length3Count);
}
}
```
阅读全文