1、基本介绍
2、应用实例
package search;
public class SeqSearch {
public static void main(String[] args) {
int[] arr = {1, 9, 11, -1, 34, 89};
int res = seqSearch(arr, 9);
if (res != -1) {
System.out.println("查找成功!");
System.out.println("元素下标:" + res);
} else {
System.out.println("查找失败!");
}
}
private static int seqSearch(int[] arr, int val) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] == val) {
return i;
}
}
return -1;
}
}