设计一个小英汉词典,其中英文单词的个数为30(单词可自己任选),从键盘输入单词,程序将单词的中文解释输出,若没有找到,则输出:not found in our dictionary!
程序员文章站
2022-05-04 14:16:53
...
设计一个小英汉词典,其中英文单词的个数为30(单词可自己任选),编程序,从键盘输入单词,程序将单词的中文解释输出,若没有找到,则输出:not found in our dictionary!
//import java.io.*;
import java.util.*;
//import java.util.Scanner;
public class UseOfDictionary {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] englishWords=new String[]{"computer","university","people","student","economics","me","our","so","import","implments","interface","final","public","dictionary","english","chinses","simple","social","why","difficult","simple","close","beautiful","omit","adequate","circumstance","abolish","vacant","reluctant","excessive"};
String[] chineseTranslation=new String[]{"n.计算机","n.综合性大学","n.人们、人民","n.大学生","n.经济学","n.我","n.我们的","n.所以","n.传入;引入","n.实施;执行;实现","与…连接;接合","最后的;","公众的","词典","英语","中文","简单的","社会的","为什么","困难的","简单的","近的","漂亮的","遗漏","充足的","情况","废除","空闲的","不情愿的","过多的"};
Map<String,String> dictionary=new TreeMap<String,String>();
for(int i=0;i<englishWords.length;i++)
dictionary.put(englishWords[i], chineseTranslation[i]);
System.out.println("请从键盘上输入你想要翻译的单词:");
Scanner input=new Scanner(System.in);
String userword=input.next();//输入数据
if(dictionary.get(userword)!=null)
{
System.out.println(dictionary.get(userword));
}
else
System.out.println("not found in our dictionary!");
}
}
上一篇: 1.常用turtle功能函数