I wrote a code that reads all words from a text, counts all the unique words, and writes a new array with all the unique words and the number of times that word is repeated on the text. For one reason when I execute it, the program treats all the words as unique and on the "if" loop the condition becomes "false" for all the words. Do you know what should I change from my code to make it compare the words properly? Thanks!
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);
}
}