⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wordcount.java~2~

📁 小程序
💻 JAVA~2~
字号:
package mypackage;import java.util.*;import java.io.*;public class WordCount { public static void main(String[] args) {   String filename = null;   double[] b = new double[26];   int[] a = new int[26];   for (int i = 0; i < 26; i++) {     a[i] = 0;   }   System.out.println("Enter the file's name");try{    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));   filename=br.readLine();   }catch(Exception e){      System.out.println("Error in reading in");}//计算频率    try {     BufferedReader inputStream = new BufferedReader(new FileReader(filename));     int letterOfNumber = inputStream.read();     int count = 1;     int n = 0;     while (letterOfNumber != -1) {       if (letterOfNumber >= 65 & letterOfNumber <= 90) {         n = letterOfNumber - 65;         a[n] = a[n] + 1;       }       else if (letterOfNumber >= 97 & letterOfNumber <= 122) {         n = letterOfNumber - 97;         a[n] = a[n] + 1;       }       count++;       letterOfNumber = inputStream.read();     }   //显示输出     System.out.println("26个英文字母的出现频率为:");     for (n = 0; n < 26; n++) {       b[n] = (double) (a[n] * 100) / count;       System.out.println( (char) (n + 97) + ":" + b[n] + "%");     }     inputStream.close();         }         catch (FileNotFoundException e) {           System.out.println("Errors123");         }         catch (IOException e) {           System.out.println("Errors");         }//查单词the出现的次数*******************************************int nn=0;try {     BufferedReader inputStream2 = new BufferedReader(new FileReader(filename));     String line = inputStream2.readLine();     int m=0;     while(line!=null)   {       StringTokenizer wordFinder=new StringTokenizer(line," /n.,;!?//");        while(wordFinder.hasMoreTokens())       {String an=wordFinder.nextToken();          if((an.toLowerCase()).equals("the"))             { m=m+1;}       nn++;           }        line=inputStream2.readLine();   }     System.out.println("单词the出现的次数为"+m);      System.out.println(nn);     inputStream2.close(); }  catch (FileNotFoundException e) {        System.out.println("Errors123");      }  catch (IOException e) {        System.out.println("Errors");   }//统计各单词出现次数*************************************************try {  BufferedReader inputStream3 = new BufferedReader(new FileReader(filename)); String line3=null; String[] word=new String[nn]; int[] wordCount=new int[nn]; for(int i=0;i<nn;i++)   wordCount[i]=0; line3=inputStream3.readLine(); int i=0; int mm=0; while(line3!=null) {StringTokenizer wordFinder3=new StringTokenizer(line3," /n.,;!?//");   while(wordFinder3.hasMoreTokens())   {String an=wordFinder3.nextToken();     for(int j=0;j<i;j++)   {if(word[j]==an)      { wordCount[j]=wordCount[j]+1;  mm--;      }       }    if(mm==i)        { word[i]=an ;         wordCount[i]=wordCount[i]+1;       i++;}      mm=i; }     line3=inputStream3.readLine();     }int nnn=i;System.out.println(nnn);inputStream3.close();//显示输出System.out.println("各个单词的出现次数为:");for(int j=0;j<nn;j++)       System.out.println(word[j]+wordCount[j]);} catch (FileNotFoundException e) {          System.out.println("Errors123");        }    catch (IOException e) {          System.out.println("Errors");     } }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -