【发布时间】:2014-03-10 13:58:03
【问题描述】:
我们被要求创建一个能够添加、编辑和搜索数据的学生和教师目录。在搜索部分,我的老师要求输出将显示与搜索中的输入匹配的所有结果。
样本输出:
search name: ab
output:
1. **ab**a, josep jr v. [IV - Garent]
2. **ab**acada, willie f. [III - Waling2x]
3. **ab**zal, louie b. [i - Mercury]
Press the number for details. Zero(0) back to the menu.
Press you choice:
如何使用这样的输出进行搜索?
我已经有了
public void search(){
System.out.print("search name : ");
try {
searchName = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
searchCount = 0;//for search
for(int i = 0; i<count; i++){
if(personList.get(i).getName().equals(searchName)){//for search
searchCount = i;
break;
}
}
System.out.println(personList.get(searchCount).getName() +" "+ personList.get(searchCount).getAge());
}
String searchName = "";//for search, store search name
int searchCount = 0;//for search
【问题讨论】:
-
使用
contains代替equals进行搜索
标签: java search directory find