【发布时间】:2018-01-21 17:42:30
【问题描述】:
我想计算每个句子的单词数我写的代码但是计算句子中每个单词的字符这是我的代码
public static void main(String [] args){
Scanner sca = new Scanner(System.in);
System.out.println("Please type some words, then press enter: ");
String sentences= sca.nextLine();
String []count_words= sentences.split(" ");
for(String count : count_words){
System.out.println("number of word is "+count.length());}
}
【问题讨论】:
-
计算空格数 " " + 1
-
欢迎来到 Stack Overflow!请查看我们的SO Question Checklist 以帮助您提出一个好问题,从而得到一个好的答案。