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,
I appreciate
******************************************//
***********************************************
import javax.swing.JOptionPane;
/**
*
* @author mesfin
*/
public class OwnWhileProject {
private static int i;
public OwnWhileProject(){
}
public static void main(String[] args) {
// Declare and initialize String array variable called names.
String names
[]={"Beah","Bianca","Lance","Belle","Nico","Yza","Gem","Ethan"};
// This is the search string we are going to use to search the
array.
String searchName = JOptionPane.showInputDialog("Enter either
\"Yza\" or \"noname\"!");
// Declare and initialize boolean primitive type variable
calld foundName.
boolean foundName =false;
while ( i < names.length ) {
i++;
if (names [i ].equals(searchName)){
foundName =true;
if (foundName)
JOptionPane.showMessageDialog(null, searchName + " is
found!");
else
JOptionPane.showMessageDialog(null, searchName + " is
not found!");
break;
}
}
}
}
--
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