【发布时间】:2013-12-03 01:48:20
【问题描述】:
帮助比较names1[middle].compareTo (value) 行。我收到以下编译器错误:
1 error found:
compareTo(java.lang.String) in java.lang.String cannot be applied to (int)
这是我的代码
public int indexOf(String word)
{
public int getIndex(String [] names1, int value)
{
int bottom = 0;
int top = names1.length-1;
int middle;
boolean found = false;
int location = -1;
while (bottom <= top&& !found)
{
middle = (bottom + top) / 2;
if (names1[middle].equals (value))
{
found = true;
location = middle;
}
else if (names1[middle].compareTo (value))
{
bottom = middle +1;
}
else
{
top = middle -1;
}
return location;
}
}
【问题讨论】:
标签: java arrays algorithm sorting binary-search