Hi guys
Im trying to do this question but I've been stuck on it for ages and despite how much I change it it wont work so if somebody could help that would be great. The question is to read in a word from the user and each time display how many times the word has occured like this
Success
0 previous occurrences
breeds
0 previous occurrences
success
1 previous occurrences
success
2 previous occurrences
This is the program I have
import java.util.*;
class Question2
{
public static void main(String[] args)
{
System.out.println("Enter a word:");
int count = -1;
ArrayList<Object> words = new ArrayList<Object>();
while (!Console.endOfFile())
{
String readWord = Console.readString();
words.add(readWord);
for (int i = 0; i < words.size() ; i++ )
{
if (words.get(i) == readWord)
{
count++;
}
}
System.out.println(count + " previous occurances.");
System.out.println("Enter a word:");
count = -1;
}
}
}
Any help would be greatly appreciated
Thanks

