java结业作业_急求JAVA设计答案,结课考试作业!!!!

展开全部

有个小点的程序,只是统计字的  没有统e68a84e8a2ad3231313335323631343130323136353331333431343064计词的 可以参考下public class WordCount {

public HashMap count(File file) {

HashMap map = new HashMap();

long count = 0;

String regex = "[\\u4e00-\\u9fa5]";

try {

BufferedReader in = new BufferedReader(new FileReader(file));

String line = in.readLine();

while (line != null) {

Pattern p = Pattern.compile(regex);

Matcher m = p.matcher(line);

while (m.find()) {

count++;

String word = m.group();

if (map.containsKey(word)) {

map.put(word, map.get(word) + 1);

} else {

map.put(word, 1);

}

}

line = in.readLine();

}

} catch (Exception e) {

System.out.println("File error");

}

System.out.println("字数: " + count);

return map;

}

public static void main(String[] args) {

File file = new File("D:\\dou.txt");

WordCount wc = new WordCount();

System.out.println("使用汉字数目: " + wc.count(file).size());

}

}

运行结果:

e479ca66b911a79dcb92d6c92750c190.png

文件内容:

fa7ce2d34166547320ea087c20aef341.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值