kotlin/java

HashMap 예제

slow333 2023. 1. 6. 17:29

key ,value / getKey(), getValue(), containsKey();

 

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

public class HashMapEx {
  public static void main(String[] args) {
    HashMap map = new HashMap<>();

    map.put("slow", "1234");
    map.put("slow33", "0000");
    map.put("kalpa", "1111");

    Scanner sc = new Scanner(System.in);

    int count =0;

    while (count <= 10) {
      System.out.println("ID를 입력하세요");

      String id = sc.nextLine().trim();

      System.out.println("Password를 입력하세요.");

      String pass = sc.nextLine().trim();

      if (!map.containsKey(id)) {
        System.out.println("입력하신 ID가 없음");
        continue;
      }
      if (!(map.get(id).equals(pass))) {
        System.out.println("ID/Pass 다름");
        continue;
      } else {
        System.out.println("정상 로그인");
        System.exit(0);
      }
      count++;
    }
  }
}