> The following program compares 2 files
> with words. If the word in one file is present
[quoted text clipped - 12 lines]
> String line1 = reader1.readLine();
> String line2 = reader2.readLine();
--> boolean found = false;
> while(line1 != null)
{
--> found=false;
--> //reset reader2 to start of file
> while(line2 != null && !found)
{
> if(line1.equals(line2))
{
> --> found=true;
> }
> line2 = reader2.readLine();
> }
-> if(!found)
-> {
-> System.out.println(line1 + " Spelling
Incorrect"); -> }
-> else
-> {
-> System.out.println(line1 + " Spelling correct");
-> }
-> line1 = reader1.readLine();
>
> }
[quoted text clipped - 3 lines]
> }
>
You're almost there. Instead of having your new if statement test when
line1 does not equal line2, you could set a boolean flag in your second
while loop. The flag is set to true if a match is found. Then you could
have your if statement test that flag.
You then just need to reset the flag to false before a new word is
searched for.
I also noticed that your code will only work if the input is in
alphabetical order. You need to reset reader2 to the start of the file
after each word is checked. This will also solve the problem you had
where the program stops when an incoreect word is found. (That was
happening because reader2 just gets to the end of your dictionary file
and then jumps out of the loop).
Hope thats useful.
#sean#.