算法:线性查找(重点isFlag标志)
作者:互联网
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("很遗憾,没有找到奥");
}
}
}
标签:arr,String,BB,isFlag,System,算法,查找,out 来源: https://www.cnblogs.com/helloworld0903/p/11456502.html