Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- HashMap <String, String> MyDictionary = new HashMap<String,String>(16);
- // key--->(group) : value -->(album)
- MyDictionary.put("Three Days Grace" , "One-X");
- MyDictionary.put("AC/DC" , "Rock or Bust");
- MyDictionary.put("Linkin Park" , "Hybrid Theory");
- MyDictionary.put("Ice cream" , "Животът е един");
- MyDictionary.put("B.T.R" , "7 Ballads");
- MyDictionary.put("Disturbed" , "Immortalized");
- System.out.println();
- // размер на речника
- System.out.println("HashMap Size: " + MyDictionary.size());
- System.out.println();
- // избираме дали ще е група или албум
- System.out.print("Please input group or album : ");
- String choice = scan.nextLine();
- if (choice.equalsIgnoreCase("album")) {
- System.out.println();
- System.out.println("Please input album:");
- String name = scan.nextLine();
- System.out.println();
- for (Map.Entry<String, String> items : MyDictionary.entrySet() ) {
- if (items.getValue().equals(name)) {
- System.out.printf("The album %s is by %s." , items.getValue() , items.getKey());
- }
- }
- }
- if (choice.equalsIgnoreCase("group")) {
- System.out.println();
- System.out.println("Please input group: ");
- String name = scan.nextLine();
- for (Map.Entry<String, String> items : MyDictionary.entrySet() ) {
- if (items.getKey().equals(name)) {
- System.out.printf("The group is %s with album %s." , items.getKey() , items.getValue());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement