good day…
i have a problem in searching my entries in my addressbook program… i already search them… but i’m having problem with showing the “Name not found!” message if the name is not yet saved in my addressbook. Can you help me figure out what’s wrong with this…
public void searchEntry() {
int notfound = 0;
SName = JOptionPane.showInputDialog("Enter Name to find: ");
for (int i = 0; i < counter; i++) {
if (entry[i].getName().equals(SName)) {
JOptionPane.showMessageDialog(null, entry[i].getInfo2());
}else{
notfound++;
}
if (notfound != 0){
JOptionPane.showMessageDialog(null, "Name Not Found!");
}
}
}
Can you help me show the “Name not found” msg… thnx in advance
move this:
outside your for loop.
I also just realized that you’re probably going to have this shown up for every single one, because you’re triggering even if it’s not found once. Try something like this: