(java)输入一字符串,判断是否为Java关键字
关键字是一行一行保存的~我的思路是读取出来和输入的进行匹配~不太清楚程序怎么写~请高手们指点一二~...
关键字是一行一行保存的~我的思路是读取出来和输入的进行匹配~
不太清楚程序怎么写~请高手们指点一二~ 展开
不太清楚程序怎么写~请高手们指点一二~ 展开
2个回答
展开全部
public class KeywordChecker {
private List<String> keywords = loadKeywords();
public boolean isKeyword(String input) {
if (keywords.contains(input)) {
System.out.println(input + "是关键字");
return true;
}
return false;
}
private void loadKeywords() {
keywords = new ArrayList<String>();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\keyword.txt")));
String line;
while ((line = br.readLine()) != null) {
keywords.add(line);
}
} catch (Exception e)
e.printStackTrace();
}
}
}
private List<String> keywords = loadKeywords();
public boolean isKeyword(String input) {
if (keywords.contains(input)) {
System.out.println(input + "是关键字");
return true;
}
return false;
}
private void loadKeywords() {
keywords = new ArrayList<String>();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\keyword.txt")));
String line;
while ((line = br.readLine()) != null) {
keywords.add(line);
}
} catch (Exception e)
e.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询