java学习记录——数组查找(在数组中查找并输出你所需要的数据)


 
import java.util.Scanner;
public class ShuZuChaZhao{
	public static void main(String[] args){
		String[] name = {"张三","李四","王五","赵云","关羽"};
		Scanner in = new Scanner(System.in);
		System.out.println("请输入你要查找的人的姓名:");
		String Name = in.next();
		boolean flag = false;
		for(int i = 0;i < name.length;i++){
			if(Name.equals(name[i])){
				flag = true;
				break;
			}
		}
		if(flag){
			System.out.println("找到 " + Name + " 了。");
		}else{
			System.out.println("没有找到 " + Name);
		}
	}
}

 

你可能感兴趣的:(java)