51,410
社区成员
发帖
与我相关
我的任务
分享
String[] reservedWords ={ "auto", "break", "case", "char", "const", "continue", "default",
"do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "int", "long", "register", "return",
"short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void",
"volatile", "while" };
char[] word=new char[20];
word[0]='s';
word[1]='h';
word[2]='o';
word[3]='r';
word[4]='t';
String str=new String(word);
System.out.println("str"); //输出short
int i=Arrays.binarySearch(reservedWords, str2);
System.out.println(i); //输出-22
for(String a:reservedWords) {
if(str.equals(a)) {
System.out.println("YES"); //不输出YES
}
}