0
我有一個包含名稱列表的文件。我必須在列表中進行搜索並打印出我搜索的兩個名稱之間的所有名稱。這裏是我的代碼:java二進制搜索通過名稱列表打印兩個名稱之間的所有名稱
case '5'://broken
System.out.println("Enter the first "last name" of the search.");
String fLast= console.next();
System.out.println("Enter the second "last name" of the search.");
String lLast = console.next();
String temp ="";
if(fLast.compareTo(lLast)<0)
{
temp=lLast;
lLast=fLast;
fLast=temp;
}
nameToNameSearch(fLast,lLast);
break;
public void nameToNameSearch(String name1, String name2)
{
ExtPerson[] nameToName = new ExtPerson[nMembes];
for(int x=1;x<nMembers-1; x++)
{
if(bookMembers[x].lastName.compareTo(name1)==0|| bookMembers
[x].lastName.compareTo (name1)>0)
{
if(bookMembers[x].lastName.compareTo(name2)==0|| bookMembers
[x].lastName.compareTo(name1)<0)
{
int add=0;
nameToName[add]=bookMembers[x];
add++;
}
}
我將排序名稱,然後使用正則表達式從名稱的toString()中提取列表...兩行代碼。 – Bohemian