import java.util.HashMap;
import java.io.*;
class Dictionary
{
private HashMap words = new HashMap();
public void setDictionary(HashMap words)
{
this.words = words;
}
public static String word;
public boolean search() //(String word)
{
if(words.containsKey(word))
return true;
else
return false;
}
}
public class DictionaryTest {
public static void main(String[] args)
{
Dictionary dic = new Dictionary();
HashMap map = new HashMap();
File read = new File("D:\\Administrator文档和收藏夹\\java\\dictionary.txt");
try
{
BufferedReader br = new BufferedReader(new FileReader(read));
String line = null;
line = br.readLine();
while(line!=null)
{
String[] words = line.split(";");
for(int i = 0; i < words.length; i ++)
{
map.put(words[i],words[i]);
}
line = br.readLine();
}
br.close();
dic.setDictionary(map);
BufferedReader cin = new BufferedReader( new InputStreamReader( System.in ) );
Dictionary.word = cin.readLine();
System.out.println("search words of search in dictionary, result is " + dic.search());
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
那.......我写了一大堆,只能实现查找,但m和n不太清楚什么意思,不知道要怎么实现,而且我觉得学的很乱,能帮我修改下么
还有,要一次查找多个,我想的是用BufferedReader的readLine,但貌似不行,能给我点思路么?