public class Test4 {
static Map<String, String> map = new TreeMap<String, String>();
static {
map.put("watermelon", "西瓜");
map.put("banana", "香蕉");
map.put("strawberry", "草莓");
map.put("apple", "苹果");
}
public static void main(String[] args) {
System.out.println("请输入单词");
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str1 = sc.nextLine();
if(str1.equals("退出")){
return;
}
else if (map.containsKey(str1)) {
System.out.println(map.get(str1));
} else{
System.out.println("次单词为新词,添加意思");
Scanner sc1 = new Scanner(System.in);
String str2=sc1.nextLine();
map.put(str1, str2);
System.out.println("添加成功。");
}
}
}
}