It is simple probably but I have no idea how to make it. Help The problem is at the end of the code.
*****I would like to have a result like this 556668 and I've got like this:
[2, 22, 222, 3, 33, 333, 4, 44, 444, 5, 55, 555, 6, 66, 666, 7, 77, 777, 7777, 8, 88, 888, 9, 99, 999, 9999][2, 22, 222, 3, 33, 333, 4, 44, 444, 5, 55, 555, 6, 66, 666, 7, 77, 777, 7777, 8, 88, 888, 9, 99, 999, 9999][2, 22, 222, 3, 33, 333, 4, 44, 444, 5, 55, 555, 6, 66, 666, 7, 77, 777, 7777, 8, 88, 888, 9, 99, 999, 9999]**
My code:
changingLettersOnNumbersAndMap("KOT");
static public void changingLettersOnNumbersAndMap(String letters) {
Map<Character, String> map = new HashMap<>();
String numbers = "";
map.put('A', "2");
map.put('B', "22");
map.put('C', "222");
map.put('D', "3");
map.put('E', "33");
map.put('F', "333");
map.put('G', "4");
map.put('H', "44");
map.put('I', "444");
map.put('J', "5");
map.put('K', "55");
map.put('L', "555");
map.put('M', "6");
map.put('N', "66");
map.put('O', "666");
map.put('P', "7");
map.put('Q', "77");
map.put('R', "777");
map.put('S', "7777");
map.put('T', "8");
map.put('U', "88");
map.put('V', "888");
map.put('W', "9");
map.put('X', "99");
map.put('Y', "999");
map.put('Z', "9999");
for (int i = 0; i < letters.length(); i++) {
char charAt = letters.charAt(i);
if (map.containsKey(charAt)) {
Collection<String> values = map.values();
Set<Map.Entry<Character, String>> entries = map.entrySet();
numbers = numbers + entries.stream().map(Map.Entry::getValue).collect(Collectors.toList());
}
}
System.out.println(numbers);
}