2020-09-27日报博客-周一

1.学到的东西:

package Test1;

import java.io.*;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;

public class TextReader {
    public static void main(String[] args) throws IOException {
        File file = new File("/home/long/Documents/Piao.txt");
        FileReader fileReader = new FileReader(file);
        int b;
        int[] count = new int[52];
        for (int i = 0; i < count.length; i++) {
            count[i] = 0;
        }
        char[] chars = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
                'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
        while ((b = fileReader.read()) != -1) {
            for (int i = 0; i < chars.length; i++) {
                if ((char) b == chars[i]) {
                    count[i]++;
                }
            }
        }
        int sunCunt = 0;
        for (int i = 0; i < count.length; i++) {
            sunCunt += count[i];
        }
        DecimalFormat df = new DecimalFormat("######0.00");
        for (int i = 0; i < count.length; i++) {
            System.out.println(chars[i] + ":"+df.format(((double)count[i]/(double)sunCunt) *100) + "%");
        }
    }
}

2.遇到的问题:

3.明日计划:继续学习Java

posted @ 2020-09-28 19:57  巩云龙  阅读(41)  评论(0编辑  收藏  举报