Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class hashmap_homework {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- HashMap<String, String> MyDictionary = new HashMap<String, String>(16);
- MyDictionary.put("Virgo", "Deva");
- MyDictionary.put("Travis Scott", "Utopia");
- MyDictionary.put("Pet Shop Boys", "Hotspot");
- MyDictionary.put("Post Malone", "Beerbongs & Bentleys");
- System.out.println();
- System.out.println("My Dictionary: " + MyDictionary);
- System.out.println();
- for (int i = 0; i < 2; i++) {
- System.out.println("Choose searching by 1: Singer / 2: Album");
- int answer = scan.nextInt();
- if (answer == 1) {
- for (int j = 0; j < 2; j++) {
- System.out.println("Enter singer name: ");
- String SingerName = scan.nextLine();
- for (Map.Entry<String, String> items : MyDictionary.entrySet()) {
- if (items.getKey().equals(SingerName)) {
- System.out.println("Album: " + items.getValue());
- }
- }
- }
- } else {
- for (int k = 0; k < 2; k++) {
- System.out.println("Enter singer album: ");
- String SingerAlbum = scan.nextLine();
- for (Map.Entry<String, String> items : MyDictionary.entrySet()) {
- if (items.getValue().equals(SingerAlbum)) {
- System.out.println("Singer: " + items.getKey());
- }
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment