package TestOne.dog;
import TestOne.panda.Search;
public class TestSearch {
public static void main(String[] args) {
int[] arr = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 23, 3, 32, 34, 4, 5, 5, 5, 6, 6, 56, 7, 7, 6};
int flag = 23;
new Search(flag, arr);
}
}
package TestOne.panda;
public class Search {
public Search(int flag, int[] arr) {
int index = -1;
int i = 0;
for (i = 0; i < arr.length; i++) {
if (flag == arr[i]) {
index = i;
break;
}
}
if (index == -1) {
System.out.println("该数组中没有所需查找的数");
} else {
System.out.println("index: " + index);
}
}
}