大家帮我看下哪里出问题了,为什么
为什么一输入姓名,不管有没有在链表里都会出现没记录import java.util.Scanner;
import java.util.ArrayList;
public class tellist
{
private String name;
private String surname;
private String phonenumber;
tellist(String surname,String name,String phonenumber)
{
this.surname=surname;
this.name=name;
this.phonenumber=phonenumber;
}
String getsurname()
{
return surname;
}
String getname()
{
return name;
}
String phonenumber()
{
return phonenumber;
}
public static void main(String[] args)
{
ArrayList<tellist> test=new ArrayList<tellist>();
test.add(new tellist("张","张三","1234567"));
test.add(new tellist("李", "李四", "1234568"));
test.add(new tellist("李", "李五", "1234569"));
//test.add(new tellist("王", "王六", ""));
System.out.println("请输入您要查找的姓氏:");//李
Scanner cin=new Scanner(System.in);
String surname;
surname=cin.next();
System.out.println(surname);
ArrayList<tellist> info=new ArrayList<tellist>();
for(tellist tmp:test)
if(tmp.getsurname().compareTo(surname)==0)
{
System.out.println(tmp.getname());
info.add(tmp);
}
System.out.println("");
if(info.size()==0)
System.out.println("不好意思,电话簿上没有您要查找的记录!");
else
{
System.out.println("请输入姓名:");//李四
String name;
name=cin.next();
boolean flag=false;
for(tellist tmp:info)
if(tmp.getname().compareTo(name)==0)
{
flag=true;
System.out.println(tmp.getname()+" "+tmp.phonenumber());
}
if(flag==false)
System.out.println("该用户暂无记录!");
}
}
}