There is a Map with countries as keys and capitals as values. You need to implement the method printWithSameLetter.
It should print only the country and the capital which have the same first letters.
HashMap
The same letter
Report a typo
Sample Input 1:
Australia Canberra
Belgium Brussels
Germany BerlinSample Output 1:
Belgium BrusselsWrite a program in Java 17
import java.util.*;
class MapFunctions {
public static void printWithSameLetter(Map<String, String> map) {
// write your code here
}
}
/* Do not change code below */
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Map<String, String> map = new HashMap<>();
while (scanner.hasNextLine()) {
String s = scanner.nextLine();
String[] pair = s.split(" ");
map.put(pair[0], pair[1]);
}
MapFunctions.printWithSameLetter(map);
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.