// does anyone know why I am getting this error?
import javax.swing.JOptionPane; // Error is here states "incorrect
package" the program still
//works correctly
public class MyOwnWhileProject {
/** Creates a new instance of ForLoop */
public MyOwnWhileProject() {
}
/**
* @param args the command line arguments
*/
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 int i
int i=0;
// Declare and initialize boolean primitive type variable
calld foundName.
boolean foundName = false;
// Search the String array using for loop.
// * The "names.length" is the size of the array.
// * This for loop compares the value of each entry of the
array with
// the value of searchString String type variable.
// * The equals(..) is a method of String class. Think about
why you
// cannot use "names[i] == searchName" as comparison logic
here.
while ( i<names.length) {
if (names [i].equals(searchName)) {
foundName =true;
}
i++;
}
// Display the result
if (foundName)
JOptionPane.showMessageDialog(null, searchName + " is
found!");
else
JOptionPane.showMessageDialog(null, searchName + " is not
found!");
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---