public class LinearSearch {
public static void main(String[] args) {
int[] ints = {5, 3, 4, 1, 2};
System.out.println(search(ints, 4));
}
public static int search(int[] arr, int key) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] == key) {
return arr[i];
}
}
return -1;
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-1386.html