【Java】单词统计
需求
给定英文文本文件,统计每个英文单词出现的次数,要求按字母顺序排列
- 文本
- Last fall I walked with a friend in hometown. He was recognized as the most stupid among my childhood playmates, but he has now been Number One in an enterprise.When we came to a fork, a blind man walked from another direction. Testing the road with his bamboo pole, the blind man was walking very slowly towards the road we were going to.I chatted with my friend as we were walking. I talked about my five job-hoppings within two years and the experiences I was still struggling in the plight now. My friend nodded and smiled, but he kept silent all along. After a while, I occasionally looked back and found the blind man had vanished.
- 效果
步骤
- 以文件输入流为参数,实例化Scanner对象
- 以正则表达式分隔,循环读取字符串并统计
- 输出结果
代码
package com.cxl.demo22_WordCount;
import java.io.File;
import java.io