Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- Dictionary<Integer, String> month = new Hashtable();
- // key : value
- month.put(1, "January");
- month.put(2, "February");
- month.put(3, "March");
- month.put(4, "April");
- month.put(5, "May");
- month.put(6, "June");
- month.put(7, "July");
- month.put(8, "August");
- month.put(9, "September");
- month.put(10, "October");
- month.put(11, "November");
- month.put(12, "December");
- // принтираме размера на речника
- System.out.println();
- System.out.println("NUMBER OF ELEMENTS : " + month.size());
- System.out.println();
- // принтираме елементите на самият речник
- System.out.println("DICTIONARY : " + month);
- System.out.println();
- System.out.print("--- PLEASE INPUT name OR number! --- : ");
- String choice = scan.nextLine();
- if (choice.equalsIgnoreCase("number")) {
- System.out.print("Input number: ");
- int num = scan.nextInt();
- System.out.printf("Value at key [%d] = %s", num, month.get(num));
- }
- if (choice.equalsIgnoreCase("name")) {
- System.out.print("Input name: ");
- String name = scan.nextLine();
- int key = 0;
- for (int i = 1; i <= 12; i++) {
- if (month.get(i).equalsIgnoreCase(name)) {
- key = i;
- }
- }
- System.out.printf("Key of value [%s] = %d", name, key);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement