Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class EnglishJapaneseDictionary {
- public static void main(String[] args) {
- Scanner in = null;
- try {
- in = new Scanner(System.in);
- }
- catch (Exception e) {
- System.exit(1);
- }
- Map<String, String> dict = new TreeMap<String, String>();
- while (true) {
- System.out.println("<メニュー選択> 1.追加、2.削除、3.検索、4.一覧表示、5.終了");
- int choice = new Integer(in.nextLine());
- if (choice == 1) {
- System.out.println("追加する英単語");
- String word = in.nextLine().trim();
- System.out.println("意味");
- dict.put(word, in.nextLine().trim());
- }
- if (choice == 2) {
- System.out.println("削除する単語");
- dict.remove(in.nextLine().trim());
- }
- if (choice == 3) {
- System.out.println("検索する英単語");
- System.out.println("意味は" + dict.get(in.nextLine().trim()) + "です");
- }
- if (choice == 4) {
- for (Entry<String, String> e: dict.entrySet()) {
- System.out.println(e.getKey() + " " + e.getValue());
- }
- }
- if (choice == 5) break;
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement