class ArrayTest4
{
public static void main(String[] args)
{
int[] arr = {1,2,3,6,8,9};
int index = getIndex(arr,2);
System.out.println("index = "+index);
}
public static int getIndex(int []arr, int key)
{
for (int x = 0;x<arr.length ;x++ )
{
if (arr[x] != key)
{
return x; //为什么不等于 最后的结果是 0呢、
}
}
return -1;
}
}
|
|