Originally Posted by
Norm
Post the search code you are working on.
The pseudo code I posted was a list of the steps the program could take to do the search. The search is done in a simple loop that looks at each row for the desired student id.
public static void main (String []args)
{
String Student [][] = {{"ID-0", "meow0", "superman0", "batman0"},
{"ID-1", "meow1", "superman1", "batman1"},
{"ID-2", "meow2", "superman2", "batman2"},
{"ID-3", "meow3", "superman3", "batman3"},
{"ID-4", "meow4", "superman4", "batman4"},
{"ID-5", "meow5", "superman5", "batman5"}};
String input = JOptionPane.showInputDialog(null, "Input Here");
int i;
int j = 0;
boolean foundIt = false;
search:
for (i = 0; i < Student.length; i++) {
for (j = 0; j < Student[i].length;
j++) {
if ( Student[i][j] == null ? input == null : Student[i][j].equals(input)) {
foundIt = true;
break search;
}
}
}
if (foundIt) {
JOptionPane.showMessageDialog(null, "Found the "
+ " id \n\n" + input + "\n" );
} else {
JOptionPane.showMessageDialog(null, input + " ID NOT FOUND");
}
my problem, how can i display the element in the column, using the ID that i search ?
for e.g i search
ID-3 and ID-3 column the other will also display, but in a new line, like these
meow3
superman3
batman3