zoukankan      html  css  js  c++  java
  • 哈姆雷特观后感 一把辛酸泪

    在我长时间的努力下我终于写完了那个简单的任务,我尝试了好几种方法后,终于成功了,也是醉了。

    为了能同时显示出现次数最多的字母以及次数,我在出现一次错误后改用了相似的两段程序,我成功了。

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    public class Count {
    public static void main(String[] args) {
    String path = "C:/Users/86173/Desktop/EnglishArtical.txt";
    File file = new File(path);
    int[] count=new int[26];
    int[] count2=new int[26];
    for(int i=0;i<26;i++)
    {
    char a='A';
    int n=((int)a+i);
    char des = (char)n;
    int count1 = process(file, des);
    count[i]=count1;
    System.out.println("字符" + des + "在出现" + count[i]+"次");
    }
    for(int i=0;i<26;i++)
    {
    char a='a';
    int n=((int)a+i);
    char des = (char)n;
    int count1 = process(file, des);
    count2[i]=count1;
    System.out.println("字符" + des + "出现" + count2[i]+"次");
    }
    int j=0,k=0;
    int maxIndex1 = count[0];
    int minIndex1 = count[0];
    for (int i = 0; i < count.length; i++) {
    if(maxIndex1 < count[i]){
    maxIndex1 = count[i];
    j=i;
    }
    if(minIndex1 > count[i]){
    minIndex1 = count[i];
    }
    }
    int maxIndex2 = count2[0];
    int minIndex2 = count2[0];
    for (int i = 0; i < count2.length; i++) {
    if(maxIndex2 < count2[i]){
    maxIndex2 = count2[i];
    k=i;
    }
    if(minIndex2 > count2[i]){
    minIndex2 = count2[i];
    }
    }

    if(maxIndex1>maxIndex2)
    { char a='A';
    int n=((int)a+j);
    char des = (char)n;
    System.out.println("字符" + des + "在出现的次数最多为:" +maxIndex1);
    }
    else if(maxIndex1<maxIndex2)
    { char a='a';
    int n=((int)a+k);
    char des = (char)n;
    System.out.println("字符" + des + "在出现的次数最多为:" +maxIndex2);
    }


    }

    public static int process(File file, char c) {
    int count = 0;
    BufferedReader br = null;
    try {
    br = new BufferedReader(new FileReader(file));
    String temp = "";
    while ((temp = br.readLine()) != null) {
    char[] des = temp.trim().toCharArray();
    for (int i = 0; i < des.length; i++) {
    if (des[i] == c){
    count++;
    }
    }
    }
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    try {
    br.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    return count;
    }
    }

    是多疑还是去相信 谎言背后的忠心 或许是自己太执迷 命题游戏 沿着他的脚步 呼吸开始变得急促 就算看清了面目 设下埋伏 真相却居无定处 I swear I'll never be with the devil 用尽一生孤独 没有退路的路 你看不到我 眉眼焦灼却不明下落 命运的轮轴 伺机而动 来不及闪躲 沿着他的脚步 呼吸开始变得急促 就算看清了面目 设下埋伏 真相却居无定处 I swear I'll never be with the devil 用尽一生孤独 没有退路的路 你看不到我 眉眼焦灼却不明下落 命运的轮轴 伺机而动 来不及闪躲 你看不到我 眉眼焦灼却不明下落 命运的轮轴 伺机而动 来不及闪躲 黑夜和白昼 你争我夺 真相被蛊惑 心从不退缩 这天堂荒漠 留给孤独的猎手
  • 相关阅读:
    .NET平台下Web树形结构程序设计李洪根
    [总结]Asp.net中的页面乱码的问题
    [原创]Datagrid中绑定DropDownList的例子
    [原创]TreeView的递归问题!FAQ
    [个人]我所有的Email地址!
    心情随笔(一)
    [原创]用JS做的一个打字程序(为网友qixiao)
    [转贴]一个通用的数据分页的存储过程
    [转贴]怎么样写一个XML文件到客户端
    [原创]用JS给DropDownList添加新项!
  • 原文地址:https://www.cnblogs.com/muailiulan/p/9775586.html
Copyright © 2011-2022 走看看