テキストからすべての単語を読み取り、すべての一意の単語をカウントし、すべての一意の単語とその単語がテキストで繰り返される回数を含む新しい配列を書き込むコードを作成しました。私がそれを実行すると、プログラムはすべての単語を一意として扱い、「if」ループで条件がすべての単語に対して「false」になります。単語を適切に比較するには、コードから何を変更する必要があるか知っていますか? ありがとう!
import java.util.*;
class textAnalyzer{
public static void main(String[] args){
Help hj = new Help();
hj.metode1(args[0]);
}
}
class Help{
void metode1(String filename){
In les = new In (filname); //input *.txt file
int totalWords = 0; // counter with total words from the text
int uniqueW = 0; //counter with the number of total unique words
boolean funnet = false;
String[] word = new String[30835]; //array with each unique word
int quantity[] = new int[30835]; // array the number of times a unique word is repeated on the text
while(read.endOfFile() == false) {
for(int i = 0; i < word.length; i++){
String oneWord = read.inWord();
totalWords++;
if(ord[i] == denneOrd){
found = true;
}
if(found){
quantity[i]++;
uniqueW++;
}else{
word[i] = oneWord;
}
}
totalWords++
}
System.out.println("Number words read: " + totalWords + " number unique words: " + uniqueW);
}
}