例题:
1.数组查找操作:定义一个长度为10 的一维字符串数组,在每一个元素
存放一个单词;然后运行时从命令行输入一个单词,程序判断数组是否
包含有这个单词,包含这个单词就打印出“Yes”,不包含就打印出“No”。
import java.util.Scanner;
public class a {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个单词:");
String str = sc.next();
String []word = {"campus","typical","effective","saving","current","likely","package","tuition","amount","risk"};
//定义一个flag值
boolean flag = true;
for(int i=0;i<word.length;i++){
if(word[i].equals(str)){
flag = false;
break;
}
}
if(flag){
System.out.println("No");
}else {
System.out.println("Yes");
}
}
}