How can I count repeated words in a text file, using an array?
My program is able to print out total words in the file, But how can I get my program to print the number of different words and also have printed out a list of the number of the repeated words like this:
Cake: 4 a: 320 Piece: 2 of 24
(Words with capital letters and small letters are considered the same word)
void FileReader() {
System.out.println("Oppgave A");
int totalWords = 0;
int uniqueWords = 0;
String [] word = new String[35000];
String [] wordC = new String [3500];
try {
File fr = new File("Alice.txt");
Scanner sc = new Scanner (fr);
while(sc.hasNext()){
String words = sc.next();
String[] space = words.split(" ");
String[] comma = words.split(",");
totalWords++;
}
System.out.println("Antall ord som er lest er: " + totalWords);
} catch (Exception e) {
System.out.println("File not found");
}