Cute Happy Ghost
본문 바로가기
JAVA/Practice

Hashmap이용해 단어쌍의 저장검색

by JENN_tech7 2020. 10. 30.
728x90
SMALL
package sample2;

import java.util.HashMap;
import java.util.Scanner;

public class Sample1 {

	public static void main(String[] args) {
		HashMap<String, String> dic = new HashMap<String, String>();
		Scanner in = new Scanner(System.in);
		
		dic.put("baby", "아기");
		dic.put("love", "사랑");
		dic.put("apple", "사과");
		
		while(true) {
			System.out.println("찾고싶은 단어는? ");
			String eng = in.next();
			if (eng.equals("exit")) {
				System.out.println("종료");
				break;
			}
			
			String kor = dic.get(eng);
			if (kor == null) {
				System.out.println(eng + "는 없는 단어");
			}else {
				System.out.println(kor);
			}
		}
	}

}

String kor 에 dic.get(eng)를 넣어주었다

찾고싶은 단어는? 
apple
사과
찾고싶은 단어는? 
babo
babo는 없는 단어
찾고싶은 단어는? 
s
s는 없는 단어
찾고싶은 단어는? 
apple
사과
찾고싶은 단어는? 
728x90
LIST

'JAVA > Practice' 카테고리의 다른 글

중첩반복문 빠져나가기  (0) 2020.10.30
arraylist활용한 회원가입  (0) 2020.10.26

댓글