java编程题从键盘输入一段英文,统计这段文字中单词的个数,并输出其中由四个字母组成的单词以5个一行输

 我来答
flyingFish211
2010-12-27 · TA获得超过2.1万个赞
知道大有可为答主
回答量:1.5万
采纳率:50%
帮助的人:1.1亿
展开全部
import java.util.Scanner;

public class SplitWords {

public static void main(String[] args) {

System.out.println("Please input some english words, separate with ',' or SPACE ");

Scanner scanner = new Scanner(System.in);

String input = scanner.nextLine();

String[] words = input.replace(',', ' ').replace('.', ' ').split("\\s+");

System.out.println("Total " + words.length + " separate word in " + input);

System.out.println("Words with 4 characters are as follows: ");

int count = 0;
for(String str: words){

if(count == 5){
System.out.println();
count = 0;
}

if(str.length() == 4){
System.out.print(str + "\t");
count++;
}

}

}

}
------------------
Please input some english words, separate with ',' or SPACE
Today is Christmas Day, we people in china don't celebrate it. I like china very much.
Total 16 separate word in Today is Christmas Day, we people in china don't celebrate it. I like china very much.
Words with 4 characters are as follows:
like very much
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
jlspfys
2011-01-10
知道答主
回答量:8
采纳率:0%
帮助的人:0
展开全部
scanner类JavaAPI 没事多看看啊。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式