Reply: equals method
From: Darryl Woodford (dwoodf_at_essex.ac.uk)
Date: 11/18/03
- Previous message: Anthony Borla: "Re: equals method"
- Next in thread: Anthony Borla: "Re: Reply: equals method"
- Reply: Anthony Borla: "Re: Reply: equals method"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 17 Nov 2003 16:33:20 -0800
**Firstly, apologies for posting this as a new thread. Waiting for
Easynews to turn on posting as the Uni doesn't offer a news server,
and having to post through google.**
Anthony,
Thanks for your suggestion.It certainly helped...
On reading over your suggestion, I tried adding:
for (int Counter = 0; Counter < 50000; Counter++) // Fill array
to prevent Null Errors
adic[Counter].word = new String();
which resolved the original problem, I'd filled the array as a whole,
but forgotten to fill the word part..but it is now throwing a
java.lang.ArrayIndexOutOfBoundsException: 20 with the line
adic[i].links[cnttwo] = adic[cntone].links[0];
which I guess is the second bit you were referring to..
I tried rewriting as:
--
for (int i = 0; i < adic.length; i++) { // Take each member of arrays
dictionary in turn
int cnttwo = 1; // Initialise second count variable, 1 as links[0]
already filled
for (int cntone = 1; cntone < (adic.length - 1); cntone++) { // Take
each member of arrays dictionary in turn
if (adic[i].word.equals(adic[cntone].word)) { // Compare against the
word we're looking for
adic[i].links[cnttwo] = adic[cntone].links[0]; // If it matches,
add it as next reference
//delete adic[cntone] // Delete anagram as repeat, now listed
elsewhere and to prevent multiples
cnttwo++; // Increment reference by one
}
}
}
--
So it should be comparing adic[0].word with adic[1].word, then storing
in adic[0].links[1] if found, before comparing with adic[2].word,
storing in adic[0].links[2] etc... up until the end of the array.
.
I was thinking this would prevent it going over the end of the array,
but didn't have the desired effect... I'm sure I'm missing something
simple..?
Cheers,
Darryl
- Previous message: Anthony Borla: "Re: equals method"
- Next in thread: Anthony Borla: "Re: Reply: equals method"
- Reply: Anthony Borla: "Re: Reply: equals method"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|