【发布时间】:2015-07-13 07:31:00
【问题描述】:
关键是用户的输入。 我正在尝试将 int 键与字符串 id 进行比较,以查看它们是否相等。 如果字符串 id == int 键。然后只需返回此链接。 否则,我想比较列表中的所有 id。
1. Add a student to records
2. Remove a student from records
3. Search a student from records
4. Display all students in records
5. Quit
当我输入 3 个学生时,它只比较第一个和最后一个。 我该如何解决?谢谢你的帮助:)
public Link searchStudent(int key)
{
Link temp = new Link(null,null);
temp = cursor;
int idNumber=0;
if(size>=key){
System.out.println("Ready to Search...");
for(int i = 0; i < size; i++){
System.out.println("key--->"+key);
System.out.println("id--->"+temp.getId());
idNumber = Integer.parseInt(temp.getId());
if(idNumber==key)
System.out.println("You found it!");
else
temp = cursor.next;
}
}
return temp;
}
【问题讨论】:
-
您需要提供更多代码。您的
searchStudent方法中有对明显在此方法之外初始化的字段的引用。