The same letter

Report a typo

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.

Sample Input 1:

Australia Canberra
Belgium Brussels
Germany Berlin

Sample Output 1:

Belgium Brussels
Write 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);
}
}
___

Create a free account to access the full topic