首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有Output...Not能够理解该错误

问没有Output...Not能够理解该错误
EN

Stack Overflow用户
提问于 2014-10-29 19:38:33
回答 1查看 59关注 0票数 0

这是我的字数统计程序,在一个包含大量数据的文件中,大约有3315个单词。我不想使用散列映射.I已经使用了散列映射并得到了输出,但我的任务是找到另一种方法来找到两个程序之间的频率和执行时间差(即有散列映射的程序和没有散列映射的程序)。我必须使用除散列映射或集合之外的任何方法。

请帮帮忙..

提前谢谢。

代码语言:javascript
复制
package thirdassignments;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;

public class WordFreq2 {

public void Working()
{

    FileInputStream in = null;
     try {
         in = new FileInputStream("C:/Users/kishansr/Desktop/file1.txt");
     } 
     catch (FileNotFoundException ex) {
         System.err.println("can’t open ");
         System.exit(1);
     }

     String word[]=new String[100000];
     int count[]={0},count1=0;
     Scanner input = new Scanner(in);

     //map<String,Integer> freq = new HashMap<String,Integer>();
     while (input.hasNext()) {
         count1=count1+1;
     }
     System.out.println(" Count: "+ count1);
     for(int i=0;i<=count1;i++)
     {
         String word1 = input.next().toLowerCase();
         System.out.println("word1 : " +word);
         if(word[i] != word1)
         {
             word[i]=word1;
             count[i]=1;
         }
         else if(word[i]==word1)
         {
             count[i]=count[i]+1;
         }

     }

      for (int i=0;i<count1;i++) {
         System.out.println(count[i] + " : " + word[i]);
     }


}
public static void main(String[] args) {
    // TODO Auto-generated method stub
    WordFreq2 wf = new WordFreq2();
    long startruntime = System.nanoTime();
    wf.Working();
    long endruntime = System.nanoTime();
     System.out.println("start time: "+startruntime+" ,end time :"+endruntime+" ,difference time: "+(endruntime - startruntime)+" nano seconds ");
}

}
EN

回答 1

Stack Overflow用户

发布于 2014-10-29 19:50:32

使用正则表达式模式匹配,获取第一个单词,将单词与剩余字符串进行匹配并统计其数量,打印计数并将其替换为空白,重复此过程即可完成所有单词。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26629369

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档