我编写了一个代码,它从文本中读取所有单词,计算所有唯一单词,然后将所有唯一单词以及该单词在文本中重复的次数写入一个新数组。出于一个原因,当我执行它时,程序将所有单词视为唯一的,并且在“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);
}
}