//顺序查找,线性查找
//int[] arr1 = new int[]{34,54,3,2,65,7,34,5,76,34,67}; //int target = 5; //方式1boolean flag = true; for (int i = 0; i < arr1.length; i++) {if(arr1[i] == target){System.out.println("找到了在"+i+"位置");flag = false;break;} } if(flag == true) {System.out.println("没有找到"); }//方式2 int i = 0; for (; i < arr1.length; i++) {if(arr1[i] == target){System.out.println("找到了在"+i+"位置");break;} } if(i == arr1.length) {System.out.println("没有找到"); }