package pl.codegym.task.task08.task0829;
import jdk.nashorn.internal.runtime.regexp.joni.ScanEnvironment;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/*
Aktualizacja oprogramowania
*/
public class Solution {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
Map<String, String> familys = new HashMap<>(3);
for (int i = 0; i < 3; i++) {
String city = input.nextLine();
String family = input.nextLine();
familys.put(city, family);
}
input.nextLine();
String find = input.nextLine();
Iterator<Map.Entry<String, String>> iterator = familys.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<String, String> next = iterator.next();
String key = next.getKey();
String value = next.getValue();
if(key.equals(find))
System.out.println(value);
}
}
}
Someone can help
Dyskutowane
Komentarze (1)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Karetson Java Developer
16 sierpnia 2020, 20:20
You have to put your "city" and "family" till you put empty string, not 3 times like in your code. And your If with break in loop must be after input your key "city" into your map. the order matters too. i did it in while loop.
ye i know its old ask but maybe it will help someone:)
0