ziom
package test;
public class Test {
public static void main(String[] args) {
printEachWordLength("It's great to see you here.");
System.out.println("\n---------------");
printEachWordLength("It's great to see you here.");
}
public static void printEachWordLength(String str) {
if (str == null) return;
if ("".equals(str.trim())) return;
String[] words = str.split(" ");
for (String word : words) {
if ("".equals(word.trim())) continue;
int length = word.length();
if (word.endsWith(".")) length--;
System.out.print(length+" ");
}
}
}没有考虑末尾句点前有空格的情况,如果有必要,你自己补充一下