Also remember to scan the array from 0 to < length, otherwise you risk to go 'out of bound'. To debug you can add a print out of i on the screen in every loop, this should help spotting the issue.

Cheers



Inviato da iPhone

Il giorno 15/ago/2010, alle ore 06.54, Michèle Garoche <[email protected] m> ha scritto:



On Aug 14, 9:50 pm, mesfin <[email protected]> wrote:
I have a little problem in this home work which displaying the Correct
search result ,However it does not display the wrong search result on
the dialog...I got the following Error When i insert a wrong word in
to the input dialog.

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
        at OwnWhileProject.main(OwnWhileProject.java:40)
Java Result: 1

Any one can  fox the problem,
There is a logic error in your program.
You have first to scan the whole array of names before being able to
say there is no match. That is in a first step you deal only with
foundName variable inside the while loop. Then once you know it is
true of false, you can set the result outside the while loop and print
it.
Also the increment of i should be at the end of the while loop not at
the top, otherwise you never read the first name and consequently get
an outofbounds exception.

Michèle Garoche

--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to