package com.atguigu;public class Main { public static void main(String[] args) { String[] arr=new String[]{"JJ","DD","MM","BB","GG","AA"}; //線性查找 Stri ...
package com.atguigu;
public class Main {
public static void main(String[] args) {
String[] arr=new String[]{"JJ","DD","MM","BB","GG","AA"};
//線性查找
String dest="BB";
boolean isFlag=true;
for(int i=0;i<arr.length;i++){
if(dest.equals(arr[i])){
System.out.println("找到指定的元素,位置為:"+i);
isFlag=false;
break;
}
}
if(isFlag){
System.out.println("很遺憾,沒有找到奧");
}
}
}