약 3315 단어와 같이 방대한 양의 데이터가 들어있는 파일에서 단어 수를 나타내는 프로그램입니다. 해시 맵을 사용하고 싶지 않습니다. 해시 맵을 사용하여 출력을 얻었지만, 두 가지 프로그램 (즉, 해시 맵과 프로그램이있는 프로그램) 사이의 실행 빈도와 실행 빈도를 찾는 다른 방법을 찾고 있습니다. hashmap 또는 set 이외의 다른 것을 사용해야합니다.출력 없음 ... 오류를 이해할 수 없습니다.
도와주세요 ..
미리 감사드립니다.
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 ");
}
}
while (input.hasNext()) {} 내부에서'input.next()'를 호출하는 것을 잊을 수도 있습니다. 그래서 ** 무한 ** 루프로 변환됩니다. 항상 두 루프를 동일한 루프에서 사용하십시오. – Braj
감사합니다 ... –