zoukankan      html  css  js  c++  java
  • 大二下学期学习进度(九)

    代码行数:800行

    编码时长:11h

    发表博客数量:3

    所学知识点:

    由于上周学习了map和collect方法,这周将项目统计文章中各字母和单词的频率代码编写完成。

    1.     统计文章中字母的频率

    思路为;按行从文件中读取,将获取的string分成字符数组,然后利用map函数HashMap<String, Integer> map = new HashMap<String, Integer>();String表示字母,integer表示出现的次数。

    HashMap<String, Integer> map = new HashMap<String, Integer>();

                   String string =null;

                   Integer count = 0;//每个字母的次数

                   Integer total = 0;//总共多少个字母

                   while ((string=br.readLine())!=null) {

                          char[] ch = string.toCharArray();//将获取的string分成字符数组

                          total = total + ch.length;

                          for (int i = 0; i < ch.length; i++) {

                                 ch[i] = Character.toLowerCase(ch[i]);//将所有的字母变成小写的

                                 count = map.get(ch[i]+"");

                                 if (count == null) {//字母没有出现重复;

                                        count = 1;

                                 }else {//字母出现重复,count+1;

                                        count++;

                                 }

                                 map.put(ch[i]+"", count);

                          }

                   }

  • 相关阅读:
    2021.5.10-(叶子相似的树)
    2021.5.8-N皇后(回溯)
    2021.5.6-(雪糕最大数)
    2021.4.23刷题(回溯-全排列)
    可持久化动态图上树状数组维护01背包
    Infinite String Comparision
    第6章 操作系统 存储器管理(二)
    markdown
    操作系统 第6章 存储管理(一)
    操作系统 第五章 死锁 (二)
  • 原文地址:https://www.cnblogs.com/zjl-0217/p/10933862.html
Copyright © 2011-2022 走看看