所以我需要帮助。我使用循环来检查数组。但是,我需要循环显示仅在检查数组的所有索引后才找到的名称。我已经尝试了此代码的许多变体。但是,我无法让它工作。它要么在检查所有代码之前中断,要么将 JOptionPane 框循环 20 次(这不是我想要的),要么显示正确的结果然后显示错误消息。这是我的代码:
private static String[]name= new String [20];
public static int i=0;
name[i]= JOptionPane.showInputDialog(null, "Please enter admin's name into the database:");
String search= JOptionPane.showInputDialog(null,"Please enter admin's name to check the database:");
for (int j=0;j<name.length;j++){
if (search.equals(name[j])){
JOptionPane.showMessageDialog(null,"Name : " +name[j]);
break;
else if(!search.equals(name[j])){
JOptionPane.showMessageDialog(null, name[j]+ "was not found");
}
}
相关分类