我正在尝试生成将搜索从数组末尾开始的元素并从头开始工作的代码,直到找到我要查找的内容。到目前为止我有这个,但它似乎没有工作:
for (int i = randomList.length - 1; i > 0; i--)
{
if (randomList[i].equals(findThis))
{
System.out.println("The index of what you're looking for in the array is: " + i);
}
}
当我编译并运行它时,它会产生与此相同的答案:
for (int j = 0; j < randomList.length; j++)
{
if (randomList[j].equals(findThis))
{
System.out.println("What you're looking for is located at this index: " + j);
}
}
这很奇怪,因为它从数组的前面开始,一直到最后。我很感激所有的帮助!