//测试类
public class look_1 {
public static void main(String[] args) {
int[] arr = { 3, 6, 4, 8, 5 };
int index = look(arr, 8);
System.out.println(index);
}
//查找功能
public static int look(int[] arr, int a){
int index = -1;
//遍历数组
for (int i = 0; i < arr.length; i++) {
//循环查找a
while (arr[i] == a) {
index = i; // 重新赋值
break;
}
}
return index;
}
}
|
|