JAVA---线性查找

package lll;

public class Test {
	public static void main(String[] args) {
		String[] str=new String[]{"aa","bb","cc","dd","ee"};
		//要查找的字符串dest
		String dest="cc";
		boolean isFlag=true;
		for(int i=0;i<str.length;i++){
			if(dest.equals(str[i])){
				System.out.println("找到了!位置是"+i);
				isFlag=false;
				break;
			}
		}
		if(isFlag){
			System.out.println("抱歉,没有找到!");
		}
	}
}

posted @ 2022-01-05 17:48  ice--cream  阅读(15)  评论(0编辑  收藏  举报