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);

                          }

                   }

  • 相关阅读:
    笔记:多线程访问ConcurrentHashMap对key加锁
    根据第三列去重
    Correct the classpath of your application so that it contains a single, compatible version of org.apache.log4j.ConsoleAppender
    python 中将源配置为阿里
    criteria两个 判断
    git flow
    sqlmap用法详解
    MongoDB 入门
    MongoDB 手册
    OWASP TOP 10简单介绍
  • 原文地址:https://www.cnblogs.com/zjl-0217/p/10933862.html
Copyright © 2011-2022 走看看